我有一个ajax调用,并且在将页面调用到另一个URL之后,尝试将页面重定向。但是,它只是刷新页面。我该怎么做才能重定向我的页面?
<button onclick="SignUp()" class="btn btn-success text-center">Submit Information</button>
function SignUp() {
var first_name = document.getElementById('first_name').value;
var last_name = document.getElementById('last_name').value;
$.ajax({
type: 'POST',
url: 'signup.php',
data: { "first_name": first_name, "last_name": last_name },
async: false,
success: (function () {
window.location.href = "http://stackoverflow.com";
})
});
}
利用
window.location.href = "http://stackoverflow.com";
由于按钮的形式是默认行为,因此提交
所以你必须type="button"
像这样添加到按钮
<button type="button" >Submit Information</button>
您需要使用 return false
的HTML
<button onclick="return SignUp()" >Submit Information</button>
的JavaScript
function SignUp() {
//Your code
return false;
};
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句