I know it is popular problem and people solves it by writing a proxy on the server side. But I want to avoid it, I have a file with hard-coded callback jsonResponse():
jsonpResponse({"keys": ["0", "2", "3", "4", "5", "6"], "promoted": [3, 10, 44, 47, 47, 31], "upcoming": [187, 14, 285, 366, 322, 225]});
and I want to get it from another domain with JQuery.ajax():
$.ajax({
type: "GET",
url: URL + filename,
dataType: "text jsonp",
jsonpCallback: "jsonpResponse",
success: function(data) {
// wrapping data
}
});
and I get an error:
XMLHttpRequest cannot load http://first.domain/filename.jsonp.
Origin http://second.domain is not allowed by Access-Control-Allow-Origin.
Is there any way to do what I want that way? Do I really have to use a proxy? If it’s true, than why?
You’re miscalling
$.ajax.You need to pass
dataType: "jsonp"; it doesn’t support multiple values.Note that since you’re using a fixed callback, you will not be able to make multiple concurrent requests, or they’ll steal each-other’s callbacks.