[英]Redirect to another page after eventlistener
I have an eventlistener that needs to run, once its run I need to redirect to another page. 我有一个需要运行的事件监听器,一旦运行,我需要重定向到另一个页面。 However when I add a window.location.href anywhere in my code it just jumps straight to the redirect and doesn't do the other code.
但是,当我在代码中的任何地方添加window.location.href时,它只会直接跳转到重定向,而不会执行其他代码。
When I comment out the redirect it runs it... 当我注释掉重定向后,它将运行...
document.getElementById('save').addEventListener('click', function () {
/*
* since the stage toDataURL() method is asynchronous, we need
* to provide a callback
*/
stage.toDataURL({
callback: function (dataUrl) {
//window.open(dataUrl);
// Send the screenshot to PHP to save it on the server
var url = 'export.php';
//alert(url);
$.ajax({
type: "POST",
url: url,
dataType: 'text',
data: {
base64data: dataUrl,
yname: thename,
yemail: theemail,
company: thecomp,
twitter: thetwitter
}
});
}
});
}); //close listener
I believe in this case you need to add a success method to your last ajax call before running the redirect. 我相信在这种情况下,您需要在运行重定向之前向您的上一个ajax调用添加成功方法。
$.ajax({
type: "POST",
url: url,
dataType: 'text',
data: {
base64data: dataUrl,
yname: thename,
yemail: theemail,
company: thecomp,
twitter: thetwitter
},
success: function() {
location.href = 'your_url';
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.