weixin_33734785 2014-11-27 10:54 采纳率: 0%
浏览 5

AJAX-解析JSON

I am attempting to match an id of a table cell with an id specified within a JSON file. If a match is found I will later do something with the description. Everytime this is ran, it skips straight to the error message. What am I doing wrong?

function getJSON(showID){
    $.ajax({
        type: 'GET',
        url:'json/tvshows.json',
        dataType: 'jsonp',
        success: function(data){
            $.each(data, function(key,tvshow){
                tvshow.description;
                var tvshowId = tvshow.id;

                if (tvshowId == showID) {
                    var description = tvshow.description;
                    console.log(description);
                }
            })
        },
        error:function(){
            console.log('Error occured in getDescription');
        }   
    }); //Ends ajax request 
}
  • 写回答

1条回答 默认 最新

  • weixin_33674976 2014-11-27 10:57
    关注

    you should be using:

    dataType: 'json',
    
    评论

报告相同问题?