Fallenreaper
Fallenreaper

Reputation: 10704

AJAX request returns 200OK but fails despite return data being JSON

Edit: In my case, The the reason that it was not returning to correct information is that I was trying to use JSONP to connect to a CORS data setup, whereas the server did not have it set up for my particular computers access. I needed to talk to someone and adjust the permissions of the config file for the server. Thats what was really going on, and i couldnt figure it out because i thought CORS and JSONP were synonymous, but in fact there are different ways they are carried out and certain server permissions which need to be set.

Brief: I have an $.ajax request which pings a server looking data. It fails, but data shows success.

Going into the Network, it SHOWS the response. I want it. Its right out of my grasp.

Errors: Says it fails, but the return is:

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

So, it means that somewhere on the client side, it was flagged. The response is:

["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"]

The Headers are:

**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

EDIT: AJAX REQUEST:

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));
    }
});

Upvotes: 0

Views: 1289

Answers (1)

Bergi
Bergi

Reputation: 665185

The response is:

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

That's no JSONP script, but plain JSON (the "padding", ie. the callback function, is missing). Since the request is cross-domain, you're not allowed to access it - and executing it as a script fails even when the resource loads with a 200 OK status.

Upvotes: 1

Related Questions