2016-12-15 4 views
0

私は2つのページA.htmlとB.htmlを持っています。 Aでは、jQueryを使用してサーバーにAjaxリクエストを行い、長いタスクが実行され、成功コールバック関数でデータが受信されます。しかし、私はAjaxリクエストの後にBに移動します。私はページBに表示するための応答を持っています。私はそれのためのソリューションを設計するのを助けてください。ありがとう前のページから作成したajaxの応答を取得します

+0

これは、サーバ側のコードが動作する必要があります。サーバ側(サーバ、言語、プラットフォーム)に関する情報を提供していないため、実行したいことが処理できるかどうかを知ることさえできませんサーバーによって –

答えて

0

ユーザーをB.htmlにリダイレクトし、そのデータをURLパラメータとして送信することができます。 A.html

function callback(data) { 
    //run code to check to make sure the data is valid, and stuff like that 


    //then redirect the user to B.html with the data as a URL parameter 
    window.location.href = "/B.html?data=" + encodeCallbackData(data); 
} 

あなたはencodeCallbackData()機能を実装する必要があります。 応答タイプがJSONであれば、それは次のようになります。B.html

if (getParameterByName("data") !== null) { 
    var json = JSON.parse(decodeURIComponent(getParameterByName("data"))); 
    // json is a variable containing the object resulting from the AJAX request. 
    //do something with json 
    //show the success message. 
} else { 
    //the user was not redirected from `A.html`. 
} 

getParameterByNamethisスタックオーバーフローの答えに見つけることができ、その後、

function encodeCallbackData(data) { 
    return encodeURIComponent(JSON.stringify(data)); 
} 

+0

私は既にページBで、私はAで定義されているコールバック関数からの応答を表示したいでしょう。 –

関連する問題