I know this question has been asked (many times) before but I still can't seem to get it right.
I want to perform an AJAX request in jQuery and get "arbitrary" contents - e.g. it may be html, text, json, img
When I perform something like the following I get the infamous No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://mydomain.com' is therefore not allowed access.
$.ajax({
url: "http://www.pureexample.com/jquery/cross-domain-ajax.html",
// dataType: "jsonp",
crossDomain: true,
success: function (data) {
console.log('success');
console.log(data);
},
error: function(request, status, error) {
console.log('Error on request. ' + request.responseText);
alert('Error on request. ' + request.responseText);
}
});
I am not serving the data, so I cannot do anything on the server-side to allow cross domain request. I believe specifying JSONP (commented out) assumes that JSON is being returned? With or without it, it does not work.
So, bottom line - is there a "simple" way to to a cross-domain request so that I may get the result and insert into a tag (e.g. html into a DIV)
Any help, or further explanation is greatly appreciated.
Thanks. Rob