2017-09-26 78 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

好吧!即时尝试这种方式! –