Reputation: 584
In my php I do like this to echo jsonp type 'json data'
echo $_GET['callback'] . '('.json_encode($arr).')';
and In my js (angularjs) I do
$http.get('http://example.com/app/?callback').
success(function(data, status, headers, config) {
console.log(data);
});
But I got this error
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.
Upvotes: 0
Views: 71
Reputation: 101730
If I'm not mistaken, you need to specify JSON_CALLBACK
as the callback parameter and use $http.jsonp()
or $http({method: 'jsonp'})
if you want to use jsonp with $http
.
You've specified nothing for the callback parameter and are trying to use $http.get()
.
Give this a whirl:
$http.jsonp('http://example.com/app/?callback=JSON_CALLBACK').
success(function(data, status, headers, config) {
console.log(data);
});
Upvotes: 1