我在我的网站上尝试了此代码,然后在其他网站上,然后通过控制台在 jquery.com 上尝试了此代码:
jQuery.ajax({
url: '/',
type: 'POST',
data: '{"test":"test"}',
contentType: 'application/json; charset=utf-8',
dataType: 'json'
});
$(document).ajaxError(function(e, jqXHR, ajaxSettings, thrownError){
console.log(thrownError);
});
因此控制台会记录以下内容:
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
我不明白为什么。看来我的代码中的一切都是正确的。
最佳答案
您传递的是字符串文字而不是对象:
data: { test: 'test' },
关于jquery - 无法发送json到服务器,出现ajax错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24589369/