0

我正在尝试获取数据,但以下脚本不起作用。你能帮我弄清楚吗?

function initialize() {
$.getJSON('http://anyorigin.com/get?url=http%3A//www.wawhost.com/appProject/fetchmarker.php&callback=?', function (data) {
localStorage.jsontext = data.contents;
});
}

localStorage.jsontext = localStorage.jsontext.replace('(', '{"temp":');
localStorage.jsontext = localStorage.jsontext.replace(')', '}');

obj = JSON.parse(localStorage.jsontext);

for(var i=0;i<=5;i++) {
document.write('<img src="' + obj.temp[i].image + '" />');
document.write(obj.temp[i].id);
document.write(obj.temp[i].location);
document.write('<br>');
}

谢谢!

4

1 回答 1

0

您确实意识到http://www.wawhost.com/appProject/fetchmarker.php提供了 jsonp。

function initialize() {
    $.getJSON('http://www.wawhost.com/appProject/fetchmarker.php?callback=?', function (data) {
        for(var i=0;i<data.length;i++) {
            document.write('<img src="' + data[i].image + '" />');
            document.write(data[i].id);
            document.write(data[i].location);
            document.write('<br>');
        }
    });
}
initialize();

http://jsfiddle.net/mowglisanu/BWfxw/

于 2013-01-10T02:30:59.690 回答