【问题标题】:In sharepoint 2010 ajax returns in error in chrome在 sharepoint 2010 中,ajax 在 chrome 中返回错误
【发布时间】: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


    【解决方案1】:

    在调用本身中尝试成功代码

    success: function(data) {
         //Write your code here
        if(data.d.results.length>0)
        {    
            var carousalDiv=item.Title;
        }
        else
        { 
            alert("Data not found")
        }
        },
      error: function() {
         alert('An error occurred');
      }
    

    希望对你有帮助

    【讨论】:

    • 它在 ie 中工作,但同样的事情在 chrome 中不起作用。所以我需要同样的东西也应该在 chrome 中工作。
    • 您是否尝试过在 ajax 调用中编写成功代码,而不是像在我的示例中那样定义另一个函数之前我遇到了与 firefox 相同的问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-27
    • 1970-01-01
    • 2013-07-31
    • 2019-03-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多