jQuery似乎不会自动解析JSON

han*_*nsi 5 string jquery parsing json

这是我的客户端jQuery代码:

$.ajaxSetup ({
   contentType: "application/json",
   datatype: 'json'
});

$.ajax({
   type: "POST",
   url: "http://localhost:1234/path",
   data: JSON.stringify(myData),
   success: function(aString){
      alert(aString);
   },
   error: function(errorData){
      alert(errorData);
   }
});
Run Code Online (Sandbox Code Playgroud)

这是服务器发出的数据:

200
Content-Type: application/json

"aStringsData"
Run Code Online (Sandbox Code Playgroud)

在警报中,显示"aStringData"的引号.但是,由于我希望从数据类型:'json'发生自动JSON.parse,我希望引用被删除.我错了吗?

the*_*dox 5

实际上dataType,参数不是datatype(JavaScript区分大小写).

您可以尝试:

dataType: 'json' // not datatype
Run Code Online (Sandbox Code Playgroud)

在你的ajaxSetup;