Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未捕获的SyntaxError:JSON中1610处的意外标记C_Javascript_Jquery_Json_Ajax - Fatal编程技术网

Javascript 未捕获的SyntaxError:JSON中1610处的意外标记C

Javascript 未捕获的SyntaxError:JSON中1610处的意外标记C,javascript,jquery,json,ajax,Javascript,Jquery,Json,Ajax,我在Ajax中遇到了一个错误 Uncaught SyntaxError:位置1610处JSON中的意外标记C ajax json的jQuery调用如下 $.ajax({ type: "POST", url: url, dataType: "json", data: "q=" +value, cache: false, success: function(data){ if(data.results.length === 0){

我在Ajax中遇到了一个错误

Uncaught SyntaxError:位置1610处JSON中的意外标记C

ajax json的jQuery调用如下

$.ajax({
   type: "POST",
    url: url,
    dataType: "json",
    data: "q=" +value,
    cache: false,
    success: function(data){
       if(data.results.length === 0){
         console.log("No Data");
       }else{
         for (var i in data.results) {
            var name = data.results[i].name;
            alert(name);
         }
       }
    },
    error: function(xhr, status, error) {
        var err = JSON.parse(xhr.responseText);
        alert(err.Message);
    }
});
来自服务器的JSON是

{
"results": [

{
    "id": " 14914",
  "asd" : "25263",
    "name": "asd ",
  "label":"ad ",
  "price":"35.00"
}, 
{
    "id": " 14916",
  "asd" : "7947",
    "name": "asd dasd asd ds",
  "label":"ad ad asd a",
  "price":"145.00"
}]
}

正如您提到的
dataType:“json”
tat意味着您的js希望响应是有效的json。 确实,您的json是有效的,但是您还需要将内容类型设置为json,以便正确解析它

您需要将内容类型头设置为application/json

在php中,您可以使用:

header('Content-Type: application/json');

您是否通过浏览器控制台检查了服务器的实际响应?可能是JSON格式错误吗?我有实际响应pasted@Gags您的代码在onError处理程序中失败,该处理程序中的响应显然不是有效的JSON。@Burimi。。是的,我还认为这是来自服务器的无效JSON的情况:P。。干杯