【发布时间】:2015-06-05 09:39:09
【问题描述】:
我正在使用 ../_vti_bin/listdata.svc by jquery ajax 从 sharepoint 2010 列表中检索数据。下面是代码:
$.ajax({
type: "GET",
url: "../_vti_bin/listdata.svc/"+listName+"?$select=Title",
contentType: "application/json; charset=utf-8",
dataType: "json",
beforeSend: function (XMLHttpRequest) {
//Specifying this header ensures that the results will be returned as JSON.
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
success: generateCarousal,
error: alertError,
//complete:afterCompletion
});
function generateCarousal(data)
{
if(data.d.results.length>0)
{
var carousalDiv=item.Title;
}
else
{ alert("Data not found")}
}
function alertError(jqXHR)
{
if (jqXHR.status == 200 && jqXHR.statusText == "OK") {
alert(typeof jqXHR.responseText)
}
else {
alert(JSON.stringify(jqXHR));
}
}
这在 IE 中运行良好,即我成功获取 json 对象,但对于 chrome,它进入错误状态,状态为 200,状态文本“ok”。而且 responsetext 以字符串格式提供正确的数据,我无法使用 jquery.parseJson 将其转换为 json。
谁能解释为什么它不能在 chrome 中工作以及可能的解决方案是什么?
【问题讨论】:
标签: jquery ajax json google-chrome sharepoint-2010