2017-09-26 7 views
0

jqueryにリダイレクトプラグインを作成しようとしています。 2回リダイレクトする必要があります。最初は「購入していただきありがとうございます」、次に実際に購入した外部ページに転送してください。jqueryでitem_idを取得して外部ページに投稿

リダイレクトするとすべて正常に動作しますが、投稿した商品のitem_idや金額を取得できません。あなたが実際の購入をした外部ページに表示するための製品を投稿しているワードプレスのページです。 これは、成功ページが表示された後、「続行」ボタンをクリックした後、「/ success」ページにリダイレクトされるコードです。メッセージが5秒間表示され、実際の購入ページにリダイレクトする必要があります:

function addToListAndRedirect(item_id){ 
var email = jQuery("[name='your-email']").val(); 
var amount = jQuery("[name='vinbrevet-contact-amount']").val(); 
var subscription = { 
    ListIds: [ 
     "beeb2f48-5265-443e-960f-4f995d8c2942" 
    ], 

    ConfirmationIssue: { IssueId: "cd081857-4f30-4da1-ab5c-a7883f62d99c" }, 

    Contact: { 
     Email: email 
    } 
} 
window.location.href = "http://vinbrevet.se/success?items="+ item_id + ":" + amount; } 

コードで/成功のページ:

function redirectToExternal(item_id, amount) { 
var item_id; 
var amount = jQuery("[name='vinbrevet-contact-amount']").val();; 
    jQuery.post("http://ui.admlo.se/Api/Subscriptions/c03a4119-f6a8-4d86-b34f-f16177ec7912").always(function() { 
    window.location.replace("https://www.systembolaget.se/dryckeslista?items=" + item_id+":" + amount); 
}); 
    } 
    setTimeout("redirectToExternal()", 5000); 

私はそれがより良い方法であることを理解し...しかし、ブラウザバーからのitem_idと量を取得することが可能にIIS?最初のリダイレクト後にitem_idと金額をどのように取得する必要がありますか?ページ/成功ではitem_idとamountを表示できますが、2回目のリダイレクトでは未定義となります:未定義です。

URL例:

http://vinbrevet.se/success/?items=7487101:1(成功ページ)。

https://www.systembolaget.se/delat?items=undefined:undefined(成功ページの後にリダイレクト)

+0

の可能性のある重複した[GETパラメータから値を取得するには?](https://stackoverflow.com/questions/979975/how-to-get-the値からの値を取得) – CBroe

+0

今チェックインする:) –

答えて

0

私はこれを行うにははるかに簡単な方法を発見しました。同じソリューションではありませんが、私はかなり良いと思いますので、2度リダイレクトする必要はありません。ここにコードがあります。いつか誰かを助けることを願っています。コードには改良が必要です。改善の多くが、それは動作します:)

function addToListAndRedirect(item_id){ 
var email = jQuery("[name='your-email']").val(); 
var amount = jQuery("[name='xxxxxx-contact-amount']").val(); 
var subscription = { 
    ListIds: [ 
     "xxxxx-5265-xxxx-960f-4f995d8c2942" 
    ], 

    ConfirmationIssue: { IssueId: "xxxxxx-4f30-4da1-ab5c-a7883f62d99c" }, 
    SubscriptionConfirmedUrl: "http://xxxxxxx.se/success/", 

    Contact: { 
     Email: email 
    } 
} 
setTimeout(function() { 
    jQuery('#av_section_1').css('background-color', '#fff'); 

    jQuery('#av_section_1').html('<div style="padding: 30px; border: 1px solid #b1b2b3; margin: 50px; text-align: center; border-raius: 6px; background-color: #eee;"><h1>You are being redirected!</h1><p>Here is going to be a good text</p><br><button id="toThePage" class="btn button">Link</button></div>'); },4000); 
    jQuery.post("http://ui.xxxx.se/Api/Subscriptions/xxxxxx-f6a8-4d86-b34f-f16177ec7912", subscription).always(function() { 

    window.location.replace("https://www.xxxxxx.se/xxxxxxx?items="+item_id+":" + amount); 
}); } 
関連する問題