weixin_33725270 2018-10-19 14:55 采纳率: 0%
浏览 164

Ajax请求每个循环

function cherchePhoto(motcle) {
            var url="http://api.flickr.com/services/feeds/photos_public.gne?tags="+motcle+"&tagmode=any&format=json&jsoncallback=?";

            // Appel AJAX
            $.ajax({
                url:url,
                type: 'GET',
                dataType: 'json',
                success : function(){
                    $('#images').empty();
                    $.each(data.items, function(i,item){
                        $(document.createElement('img')).attr('src', item.media.m).appendTo("#images");

                    });
                }
            })  
}

I have this jQuery function with an ajax call and I want to build a img tag with the src attribute after #images in my html page for each images I receive from the ajax call. But I get an uncaught reference error with 'data' not defined, why ?

  • 写回答

3条回答 默认 最新

  • weixin_33724570 2018-10-19 14:58
    关注

    Because you missed data in your success callback. Try this

    success : function(data){

    评论

报告相同问题?