weixin_33709609 2016-01-10 18:04 采纳率: 0%
浏览 25

意外令牌:在ajax调用中

Got an issue with my ajax, Here is my code

var sortTable = function() {

  $("#tableid tbody tr").detach().sort(function(a, b) {

    var dataA = $(a).find("td:eq(3)").text().trim();

    var dataB = $(b).find("td:eq(3)").text().trim();

    return parseFloat(dataA.substring(1)) - parseFloat(dataB.substring(

      1));

    }).appendTo('#tableid');

  };

  // var contentType ="application/x-www-form-urlencoded; charset=utf-8";
  //
  // if(window.XDomainRequest) contentType = "text/plain";


  $.ajax({
    beforeSend: function (xhr){
      xhr.setRequestHeader("Content-Type","application/json");
      xhr.setRequestHeader("Accept","application/json");
    },
    type: 'GET',
    crossDomain: true,
    dataType: 'jsonp',
    url: 'Url here' + var,
    success: function(json) {
      //var json = $.parseJSON(data);
      for (var i = 0; i < json.results.length; i++) {
        var section = json.results[i].name;
        var tid = json.results[i].Id.slice(1);
        var price = json.results[i].minPrice;
        var url = json.results[i].url;
        var button =
        "<a class='btn btn-info'>Buy Now</a>";
        $("#tableid").append("<tr><td><img id='theImg' src='/assets/logo.png'/></td><td><b>" + section +
        "</b></td><td><b> In Stock </b></td><td><b>£" + price + "</b></td><td><b>N/A</b></td><td><b>£" + price +"</b></td><td><b>" + button + "</b></td></tr>");
        $("#tableid").find(".btn.btn-info").click(function() {
          location.href = $(this).attr("data-url");
        });
      }
      sortTable();
    },
    error: function(error) {
      console.log(error);
    }
  });

Now when i try and load the thing (debuggers in both the error and the success) the debugger activates in the error function, Stating that its status 200 etc etc. (the data is pulled back fine in postman)

In the console i get

Uncaught SyntaxError: Unexpected token :

How can i fix this? obviously nothing being appended to the table because of this.

Sam

  • 写回答

1条回答 默认 最新

  • weixin_33704591 2016-01-10 18:11
    关注

    If you're using JSONP, the response should be valid JavaScript code, like this:

    callback({a: 1, b: 2});
    

    while in your case it's probably:

    {a: 1, b: 2}
    
    评论

报告相同问题?

悬赏问题

  • ¥15 三菱变频器模块怎么检测触发
  • ¥30 求一下解题思路,完全不懂。
  • ¥30 关于#硬件工程#的问题:求一下解题思路
  • ¥15 运筹学对偶单纯行法构造扩充问题
  • ¥20 XP系统的老电脑一开机就提示找不到rundll.exe,付费求解
  • ¥15 milvus查询出来的score怎么转换成0-1之间的相似性
  • ¥15 lvgl V9移植到linux开发板
  • ¥15 VB.net中在窗体中创建一个button控件来关闭窗体,但是提示错误,我该怎么办
  • ¥15 网上下载好的程序但是arduinoIDE编程报错,运行不了,哪里出错了,能具体给改一下吗
  • ¥15 Sharepoint JS开发 付费技术指导