Reputation: 369
Before i retrieve data from my link (http://mubi-app.herokuapp.com/api/v1/home), i test it with browser, it is ok. it returns Json format, but i got error when i access that link with ajax. Thanks,
Here is my code .....
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$.ajax({
type:"GET"
, url:"http://mubi-app.herokuapp.com/api/v1/home"
, dataType:"jsonp"
, success: function(data){
debugger;
$('#result').text(data)
}
, error: function(e) {
debugger;
console.log(e)
alert(e + "Error");
}
});
});
</script>
Upvotes: 0
Views: 2688
Reputation: 388316
Since it is a cross-domain request you are trying to use jsonp request, but for that to work the server needs to support it. In this case it does not seem to be the case.
So I don't think it is possible to create a browser side call to the said API.
One possible solution is to write a server side wrapper for the said API, can in server side delegate the request to the said API.
Upvotes: 1
Reputation: 40639
You should create a jsonpcallback function
to solve your issue, like
$(document).ready(function() {
$.ajax({
type:"GET"
, url:"http://mubi-app.herokuapp.com/api/v1/home"
, dataType:"jsonp",
jsonpCallback: "localJsonpCallback",
success: function(data){
debugger;
$('#result').text(data)
}
, error: function(e) {
debugger;
console.log(e)
alert(e + "Error");
}
});
});
function localJsonpCallback(json) {
console.log(json);
}
Read http://api.jquery.com/jquery.ajax/
See this
Upvotes: 0