weixin_33698823 2017-05-01 03:56 采纳率: 0%
浏览 61

拆分ajax返回值

I think what I'm trying to do is pretty simple, but I'm stuck. I'm trying to split the returned value of my ajax function. I don't think I'm correctly specifying the return value to split. Code is below.

 <script>
 function showCars(){
   var name = document.getElementById(“carID”).value;

   $.ajax({
        url : "<%=context%>/ListCarServlet?name=" + name,
        type : "POST",
        async : false,
        success : function(data) {
                 String[2] a = data.split("|");   //<———don’t think i’m splitting return value correctly
                document.getElementById(“value1”).value = a[0];
                document.getElementById(“value2”).value = a[1];         
        }
   });
 }
 </script>
  • 写回答

2条回答 默认 最新

  • weixin_33743248 2017-05-01 03:59
    关注

    You can't write String[2] because that isn't valid JavaScript syntax. Instead you could write var a = data.split("|");. You can read more about variable declarations using var on MDN.

    For example:

    var data = "foo|bar";
    var a = data.split("|");
    console.log(a[0]); // "foo"
    console.log(a[1]); // "bar"

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料