I am trying to pull data down via JSONP with angular. I've been puzzled as to why it won't work in certain situations.
I've been able to successfully pull in this sample JSONP:
https://angularjs.org/greet.php?callback=JSON_CALLBACK&name=Brian
But when copied to a bucket on S3, I keep getting this error:
Uncaught ReferenceError: JSON_CALLBACK is not defined
The file is public and I can access it just fine with $.ajax
, but not $http.jsonp
I've tried changing the MIME type for the json file to all of the following:
None of them have allowed me to make a successfull call through the $http.jsonp
function
Ok, so this is very strange, but I eventually got it to work by changing the callback wrapper in the JSONP from JSON_CALLBACK(.......)
to angular.callbacks._0
because that's the callback function angular kept trying to call instead of JSON_CALLBACK... very weird behavior.
Not being able to see your code, I can show you what worked for me a few days ago when working with JSONP and angular:
controller('YourCtrl', ['$scope', '$http', function($scope, $http) {
var url = "https://angularjs.org/greet.php?callback=JSON_CALLBACK&name=Brian"
$http.jsonp(url)
.success(function(data) {
$scope.greeting = data;
});
}])
Then in the view, something like this should work:
<div ng-controller="YourCtrl">
{{greeting.name}} <br />
{{greeting.salutation}}
</div>
If this doesn't answer your question, try pasting in your code.
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