尝试执行以下调用时出现解析错误:
$.ajax({
cache: true,
url: "http://localhost:3000/app/test/result1",
data: "{}",
type: "GET",
jsonpCallback: "testCall",
contentType: "application/jsonp; charset=utf-8",
dataType: "jsonp",
error: function (xhr, status, error) {
alert(error);
},
success: function (result) {
alert(result);
},
complete: function (request, textStatus) {
alert(request.responseText);
alert(textStatus);
}
});
如果我直接将请求url粘贴到浏览器地址栏中,返回的结果似乎是有效的JSON:
{
"name": "The Name",
"description": "The Description"
}
我正在使用 IISnode、NodeJs 和 Express JS。我已经测试了这两种情况:
// NODE JS CODE
var app = express();
app.get('/app/test/result1', function (req, res) {
res.send({ name: "The Name", description: "The Description" });
});
app.get('/app/test/result2', function (req, res) {
res.send(JSON.stringify({ name: "The Name", description: "the Description" }));
});
任何建议表示赞赏,在此先感谢。