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 に答える