Short question: is there a way to make a jsonp request to a server, capture the request, but not parse it as javascript? I am using dataType: "jsonp text" in jQuery 1.5 but it is not working.
I'm trying access a cross-domain URL via AJAX with jsonp. The problem is that the other domain (a directory listing at my university) is very old and I doubt the server supports jsonp.
What I want is: a way to access the response from a jsonp request as plain text. Or, if I can access the raw response from a failed jsonp request -- that would work too.
Thanks in advance!
Code:
ajax_url = 'https://somesite/?searchTerm='+query+'&searchType=lastname';
var jqxhr = $.ajax({type:"GET",
url: ajax_url,
dataType:"jsonp text",
callback: "whatever",
success:function(responseData) {
$('div#content').text( responseData.slice(0, 100) );
dbg(responseData.slice(0,100));
}})
.success(function() { alert("success"); })
.error(function(obj, errStr) { alert("error"); dbg("error: " + errStr + "test: " + test.responseText + this.responseTxt);})
.complete(function() { alert("complete"); });
What you're trying to achieve won't work: jsonp can only be used if and when the server properly embed the response in a javascript function call.
Even though the server does send the file to the browser, you won't be able to access it because of security limitations: all you can do is execute said data as a script (with a script tag) or use it as a stylesheet (using a link tag) but you'll never, ever, be able to inspect the response in raw text if it's from another domain.
I suppose you tried to get the data as xml directly and that it failed (meaning the site does not support CORS). If you cannot change code server-side, then you only have two alternatives:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With