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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵