0

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));
    }
});
Fallenreaper
  • 10,222
  • 12
  • 66
  • 129
  • Can you post the code where you make the AJAX request? – taylorc93 Jul 19 '13 at 14:31
  • You are making a JSONP call? `callback:jQuery172021616409649141133_1374243099954` – epascarello Jul 19 '13 at 14:34
  • yes, the server is somewhere else, so it has to be a JSONP call. It is just weird because it returns the response in the network correctly, it seems to fail somewhere client side or something, as everything seems to be returned from the server correctly. – Fallenreaper Jul 19 '13 at 14:39
  • [SOP](http://en.wikipedia.org/wiki/Same_origin_policy)? – Bergi Jul 19 '13 at 14:42
  • JSONP gets around SOP, allowing AJAX like calls to other domains. – Fallenreaper Jul 19 '13 at 14:46
  • But is it JSONP that the server responds with? `Content-Type:application/json` doesn't make it look so. Oddly I'm getting a `302 Found Location: http://example.iana.org` when trying to send your request. – Bergi Jul 19 '13 at 14:48
  • I will say, it is unknown to me whether it is using JSONP protocols or not. Its rather weird. I go to the link, it shows the resultant text.... then i costructed it with JSON (failed because cross domain) and then JSONP returns everything except the failure function is called. – Fallenreaper Jul 19 '13 at 14:51
  • Which leads me to think that the response doesnt really have headers or anything, and it just has returned text which needs to be parsed into JSON – Fallenreaper Jul 19 '13 at 14:53
  • To be precise, JSONP does not allow Ajax calls to other domains. JSONP is simply the process of dynamically including JavaScript script with only a function call. The SOP does not apply to JS scripts (otherwise CDNs would not work). jQuery just abstracts from this difference. – Felix Kling Jul 22 '13 at 19:19

1 Answers1

1

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.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375