Using jQuery to get jsonp data returns invalid label error
I have been using jquery ajax method to get the json data. I have used both jQuery.getJSON and jquery.ajax methods but I keep getting the same error in my console. Invalid label meta I just want to display the some of the json data inside a div , is there something wrong with the json file the java script works fine with other json files. I dont know how to parse this particular json file.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type = text/javascript>
$(document).ready(function(){
$.ajax({
url: 'http://api.yipit.com/v1/deals/?key=TMBYhd3hkzfCntMb&limit=20&division=boston',
dataType: 'jsonp',
success: function(data){
console.log(data);
开发者_如何学运维 }
});
return;
});
</script>
I just tried to parse the data but I am not able to see the result. In the console I get a error saying field.deals.url not defined ?
I am also able to see jQuery16209054896509423064_1311611178838({ on top of the meta how can I parse this file ?<script type = text/javascript>
$(document).ready(function(){
$.ajax({
url: 'http://api.yipit.com/v1/deals/?key=TMBYhd3hkzfCntMb&limit=20&division=boston&callback=?',
dataType: 'jsonp',
success: function(data){
$.each(data.response, function(i, field){
$('#display').append('<p>url : ' + field.deals.url+ '</p>');
if ( i == 3 ) return false;
});
}
});
return;
});
</script>
Delete jsonp: false,
you have to use JSONP in this cross domain case.
This will work:
$(document).ready(function(){
$.ajax({
url: 'http://api.yipit.com/v1/deals/?key=TMBYhd3hkzfCntMb&limit=20&division=boston',
dataType: 'jsonp',
success: function(data){
console.log(data);
}
});
});
Working example: jsFiddle
EDIT:
deals is your iterator not response
success: function(data){
$.each(data.response.deals, function(i, field){
$('#display').append('<p>url : ' + field.url+ '</p>');
if ( i == 3 ) return false;
});
精彩评论