0

現在、Phonegap と XUI を使用して Web アプリを作成しています。

XUI 経由で http リクエストを使用して、外部ドメインからデータを取得しています。

これは正しく機能しており、JSON データを正しく受け取りました。以下のデータ形式を参照してください。

({"first":"John","last":"Smith","HighScore":"75"})

だから今、私はjavascriptを使ってデータの個々のアセットにアクセスできるようにしたいと思っています.

 x$('#test').xhr(URL,function() {
    loggedin = this.responseText; // This is the data that has been received from the PHP file
    if(loggedin != '1') // If not 1 then will let them in
    {
        alert(loggedin); // Alerts with the data recieved
    }
    else // Login incorrect
    {alert('Sorry you login details were incorrect please try again.');}
});

おそらく簡単にできることはわかっていますが、それを理解できないようですので、どんな助けでも大歓迎です。

ありがとう、

ケイン

4

1 に答える 1

1

JSON オブジェクト アクセサーの構文はですobject.keythis.responseText{"first":"John","last":"Smith","HighScore":"75"}Smiththis.responseText.last

アラートの使用例は次のとおりです。

alert('Hello ' + this.responseText.first + ' ' this.responseText.last + '! You currently have a high score of ' + this.responseText.HighScore + ' points! Play again!');
于 2011-09-28T12:34:29.323 に答える