html代码:
<section class="main">
<form class="form-4" name="form4" id="form4" method="POST">
<p class="submit">
<button type="submit" name="submit" onclick="show()"><i class="icon-thumbs-up icon-large"></i></button>
</p>
</form>
</section>js代码:
function show(){
$.ajax({
type: "POST",
url: "check_login_points.php",
data: {test : JSON.stringify(arr)},
success: function(data) {
if(data == 0)
{
alert(" SORRY :( \n misplaced cue points.");
}
else if(data == 1)
{
document.getElementById("form4").action = "http://localhost/profile_book/login_key.php";
//alert("WELCOME !!!");
//$("#form4").attr('action', 'http://localhost/profile_book/login_key.php');
}
else if(data == 2)
{
alert("enter cue-points");
}
}
});
}当ajax函数成功时,我试图将表单操作放在javascript中。但是形式的动作似乎不起作用。建议受到高度赞赏。提前谢谢!
发布于 2015-02-27 18:28:11
冒着危险出去。假设您实际上只是问为什么表单没有提交,在这种情况下,这是因为您错过了表单提交:
var form = document.getElementById("form4");
form.action = "http://localhost/profile_book/login_key.php";
form.submit()发布于 2015-02-27 18:32:08
你不能做你想做的事,因为不同步的天性。它需要被分解成多个部分。
首先,将按钮重命名为其他东西。你会遇到麻烦的。
<button type="submit" name="btnSubmit" />其次,将表单提交绑定到jQuery,而不是内联事件。
$("#form4").on("submit", function(event) {
//cancel the submission
event.preventDefault();
//call your logic
show();
});现在,最后一件事是在设置操作后手动触发提交。
function show (){
$.ajax({
type: "POST",
url: "check_login_points.php",
data: {test : JSON.stringify(arr)},
success: function(data) {
if(data == 0) {
alert("SORRY :( \n misplaced cue points.");
} else if(data == 1) {
$("#form4").attr("action", "http://localhost/profile_book/login_key.php")[0].submit();
} else if(data == 2) {
alert("enter cue-points");
}
}
});
}https://stackoverflow.com/questions/28771817
复制相似问题