Cant display the picture when json finished loading

66 Views Asked by At

I wanna display the picture from JSON API on the smartphone, but it doesn't display now.

HTML CODE

<div id="xxx" data-theme="f" data-role="footer" align="bottom" ></div>

JAVASCRIPT CODE

$(document).ready(
    function()
    {
        $.ajax(
            {
                type:"GET",
                url: "http://lab.dboem.com/tpctax2/index.php?act=banner_app&code=json",
                dataType: "json" ,
                success: ShowData,
                error: function(data)
                {
                    alert("ERROR");
                },
            }
        );
    }
);

function ShowData(data)
{
    //alert(JSON.stringify(data));

    for( var i=0 ,cnt=data.length ; i<cnt ; ++i )
    {
        var img = '<img  src="'+data[0]["banner_img"]+'" /> ';
        $("#xxx").append('<img  src="'+data[i].banner_img+'" /> ');
    }
}
1

There are 1 best solutions below

0
Marcelo Aymone On

If your request are from the other domain you need use that:

crossDomain:true,

If your result call other function, you need use async:false parameter

async:false,

Finally, if you calling ShowData(data) function, you nees pass the requested parameter (data)

success: ShowData(data),