我希望在ajax成功状态之后将用户重定向到google.com但是当ajax成功完成时,成功功能无效或根本没有调用 ajax的代码是
$('.modal2c').click(function() {
// event.preventDefault();
var urlpost = "<?php echo $post_url; ?>";
var username1 = document.getElementById("username").value;
var password1 = document.getElementById("password").value;
var magic = document.getElementById("magic").value;
$.ajax({
url: urlpost,
method: "POST",
data: {
username: username1,
password: password1,
magic: magic
},
success: function(data) {
alert('data');
window.location.href("https://www.google.com")
},
});
});
答案 0 :(得分:-2)
您能否添加一些关于您问题的信息。请在Ajax中添加错误块以获得确切原因以了解为何会发生这种情况。
$('.modal2c').click(function () {
// event.preventDefault();
var urlpost = "<?php echo $post_url; ?>";
var username1 = document.getElementById("username").value;
var password1 =document.getElementById("password").value ;
var magic =document.getElementById("magic").value;
$.ajax({
url:urlpost,
method:"POST",
data:{username:username1,password:password1,magic:magic},
success:function(data){alert('data');
window.location.href("https://www.google.com")
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.responseText);
alert(errorThrown);
}
}); }
);