You need to be logged in to post in the forums. If you do not have an account, please sign up first.
jQuery.ajax troubles, can someone help?
I'm trying to fetch the html GET response from a webpage with this code
window.addEventListener('load', function () {start()} ,false);
function start(){
with(window){
/*Loading jQuery here */
jQuery.ajax({
url: 'http://api.jquery.com/jQuery.ajax/',
type: 'GET',
success: function(res) {
alert("Done!"); },
error: function (XMLHttpRequest, textStatus, errorThrown){
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.responseText); }
});
};
}
but I had no luck, it gives me '0' at XMLHttpRequest.status, and 'undefined' to XMLHttpRequest.responseText.
Can someone help me get out of this?
It could be that your use of with is causing trouble. It's not allowed in strict mode.
Intelligent alien life does exist, otherwise they would've contacted us. — Calendar — Extend Opera
It could also be that, unless you're calling this from jquery.com, that's a cross origin request. There's an article on dev.opera about this, but I'm not entirely sure how jQuery handles cross origin requests. From what I understand, if jQuery's server isn't set up to allow cross origin resource sharing, you won't be able to download jQuery via XHR from a user script. (You could use an extension though, as the background script can make cross origin requests.)
Opera 12.15 - Win 8 Pro x64 All my Opera tools -Tab Vault: Save tabs for later -AutoStack: tabs opened from a stack stay there
Originally posted by spadija:
It could also be that, unless you're calling this from jquery.com, that's a cross origin request
Shouldn't that result in an error in the error console?
Anyway, to expand on what I was saying, it can be ambiguous to what the with should apply precisely.
Intelligent alien life does exist, otherwise they would've contacted us. — Calendar — Extend Opera
Originally posted by Frenzie:
Shouldn't that result in an error in the error console?
Maybe if you were using plain XHR, but jQuery could be swallowing the error.
Opera 12.15 - Win 8 Pro x64 All my Opera tools -Tab Vault: Save tabs for later -AutoStack: tabs opened from a stack stay there
Originally posted by spadija:
Maybe if you were using plain XHR, but jQuery could be swallowing the error.
Ah, good point.
Intelligent alien life does exist, otherwise they would've contacted us. — Calendar — Extend Opera