尽管返回数据是JSON,但AJAX请求返回200OK但仍然失败

时间:2013-07-19 14:29:22

标签: javascript ajax json header

编辑:在我的情况下,它没有返回正确信息的原因是我试图使用JSONP连接到CORS数据设置,而服务器确实没有为我的特定计算机访问设置它。我需要与某人交谈并调整服务器配置文件的权限。这就是真正发生的事情,我无法弄明白,因为我认为CORS和JSONP是同义词,但实际上它们有不同的执行方式和某些需要设置的服务器权限。

简介:我有一个$ .ajax请求,它会ping服务器查看数据。它失败了,但数据显示成功。

进入网络,它显示响应。我要它。它完全不在我的掌握之中。

错误:说它失败了,但回报是:

{"readyState":4,"status":200,"statusText":"success"}

所以,这意味着在客户端的某个地方,它被标记了。答复是:

["Asset","AssetElementDefMap","AssetFile","AssetFileCategory","AssetFileCategoryObjectMap","AssetFilesFieldMap","AssetFilesReportMap","AssetTree","AssetType","BicUrl","CancelledUpload","CurrentValue","DataTypeInstanceMembers","DataTypeInstances","DataTypeMembers","DeviceDatabase","ElementDef","ElementDefEnvironment","ElementDefFormMap","ElementDefManual","ElementDefStructUnit","ElementDefStructUnitList","Field","FieldChoice","FieldFormScriptMap","FileType","FileTypeAssetFileCategoryMap","ForgotPassword","Form","FormScriptFunction","FormType","in_id","InspectionType","Inspector","MobileFormOSMap","MobileReportTypeFormMap","MobileReportTypeFormTypeMap","ProfileProperty","Report","ReportSubAssetMap","ReportType","ReportTypeAssetTypeMap","ReportTypeInspectionTypeMap","ReportValue","WorkingSet"]

标题是:

**Request**
URL:http://xx.xxx.xx.x/mas3/DataSources/inspecttech.inspecttech/Schema/Classes/?callback=jQuery172021616409649141133_1374243099954&_=1374243124683
Request Method:GET
Status Code:200 OK
**Request Headers**
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Authorization:Basic bmRvdG1vYnguaGluc3BlY3R0ZWNoOjU0NjdjZTg2ZTdiMzc4MTNjYmQ0ZGQ3MTM1MDJkOGVjNDNiYjUwMTU2NzJiNzAxNDczMDRjYzE5YjA5ZGIyN2EyODNiMzliNmY4YzIyN2UxNjY1MDk5NDcxYzBjOTFlODZhN2EzOTliZTgzMjliNGY1MzFjOWZhYWI3YjNkMjg1
Connection:keep-alive
Host:10.224.65.5
Referer:http://localhost:3033/BentleyFormIntegrationFrameset.aspx
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36
**Query String Parameters**
callback:jQuery172021616409649141133_1374243099954
_:1374243124683
**Response Headers**
Cache-Control:no-cache
Content-Language:en-US
Content-Length:801
Content-Type:application/json; charset=utf-8
Date:Fri, 19 Jul 2013 14:12:03 GMT
Expires:-1
Mas-License-Error-Id:NoClientLicense
Mas-License-Error-Message:Client's license is invalid.
Pragma:no-cache
Server:Microsoft-IIS/7.5
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET

编辑: AJAX请求:

var u = "myusername";
var p = "mypass";
var up = u + ":" + p;
$.ajax({
    type: "GET",
    url: "http://xx.xxx.xx.x/mas3/DataSources/inspecttech.inspecttech/Schema/Classes/",
    contentType: "application/json; charset=utf-8",
    dataType: "jsonp",
    headers: {Authorization: "Basic "+up},
    success: function (r) {
        alert("Success: " + JSON.stringify(r));
    },
    error: function (r) {
        alert("Failure: " + JSON.stringify(r));
    }
});

1 个答案:

答案 0 :(得分:1)

  

回复是:

Content-Type:application/json
["Asset","AssetElementDefMap",…,"WorkingSet"]

那不是JSONP script,但是缺少普通的JSON(“填充”,即回调函数)。由于请求是跨域的,因此您not allowed可以访问它 - 并且即使资源加载200 OK状态,脚本也会执行它。