2017-09-26 44 views
-1

更新 - 進出口工作在一個簡單的功能,點擊後您重定向到一個外部頁面與您在表單中選用的產品。事情是,我需要首先做一個重定向到「謝謝你購買」頁面,然後重定向到外部...這是我的代碼,我是如何嘗試去做的。的setTimeout對重定向功能來重定向兩次

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; 

jQuery.post("http://ui.admlo.se/Api/Subscriptions/c03a4119-f6a8-4d86-b34f-f16177ec7912", subscription).always(function() { 
    function redirectToExternal(item_id, amount) { 
    window.location.replace("https://www.systembolaget.se/dryckeslista?items="+item_id+":" + amount); 
    } 
}); 

}

和/成功

function redirectToExternal(item_id, amount) { 
    window.location.replace("https://www.systembolaget.se/dryckeslista?items="+item_id+":" + amount); 
    } 

setTimeout("redirectToExternal()", 5000); 

現在重定向的偉大工程,但我不能讓ITEM_ID和數量?我應該在/成功複製整個功能嗎?

所以是這樣的:你發佈你的購買到「/成功」頁面,5秒鐘後,它將重定向到與item_id的外部頁面。我在哪裏做錯了?

+1

這行後面什麼都沒有'window.location.href =「http://dryckesbrevet.se/success」;'會被執行,因爲你告訴瀏覽器去一個新的頁面而忘了這個。當然這很明顯?如果你想要一個第二重定向,你必須把代碼在 – ADyson

+0

「成功」頁面,這是不可能的,因爲我只好重定向到其他頁面中通過'http:// dryckesbrevet.se/success'頁並保存ITEM_ID和數量在會議和取得'http:// dryckesbrevet.se /成功' – Pritamkumar

回答

1

你成功頁面應該採取的產品ID的URL,而第二重定向腳本應該是成功的頁面上。

window.location.href = "http://dryckesbrevet.se/success"; 

下面的代碼不會像現在在不同的頁面上運行!

試着這麼做:

window.location.href = 「http://dryckesbrevet.se/success?id=」 + PRODUCT_ID;

然後把你的setTimeout()成功頁面上,搶ID和重定向!

1

不能重定向兩次。只要您設置location.href您的瀏覽器將會移動到它,並且任何進一步的操作不會生效。

你需要第二個重定向URL傳遞到第一頁,第一頁從做5秒鐘後重定向。

  1. location.href='http://dryckesbrevet.se/success&redirect='+encodeURIComponent("http://ui.admlo.se/Api/Subscriptions/c03a4119-f6a8-4d86-b34f-f16177ec7912")
  2. success頁顯示消息
  3. success頁執行setTimeout("redirectToExternal()", 5000);重定向到在&redirect=???提供的外部頁。
+0

好吧!即時嘗試這種方式! –