【问题标题】:form submit with two actions表单提交有两个动作
【发布时间】:2015-10-26 14:10:00
【问题描述】:

我正在尝试创建一个表单提交将执行两个操作的页面。在 index.php 中,第一个动作是它将使用 ajax 发送数据以保存在数据库中。第二个动作是将页面更改为 index1.php。我创建的代码成功将数据保存到数据库,但它没有更改为 index1.php。我的代码有什么问题?

index.php

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

<script>
$(document).ready(function(){
$("#submit").click(function(){
var radio1 = $("input[name=group1]:checked").val();
var radio2 = $("input[name=group2]:checked").val();
var radio3 = $("input[name=group3]:checked").val();
var radio4 = $("input[name=group4]:checked").val();
// Returns successful data submission message when the entered information is stored in database.
var dataString = '&submit1='+ radio1 + '&submit2='+ radio2 + '&submit3='+ radio3 + '&submit4='+ radio4;

if(radio1==''||radio2==''||radio3==''||radio4=='')
{
alert("Please Fill All Fields");
}
else
{
// AJAX Code To Submit Form.
$.ajax({
type: "POST",
url: "ajaxsubmit.php",
data: dataString,
cache: false,
success: function(result){
alert(result);
}
});
}
return false;
});
});
</script>

<form action="index1.php" method="post">
                <hr>
                        <label>Alignment: </label>
                        <input type="radio" name="group1" value="5"> 5
                        <input type="radio" name="group1" value="4"> 4
                        <input type="radio" name="group1" value="3"> 3
                        <input type="radio" name="group1" value="2"> 2
                        <input type="radio" name="group1" value="1"> 1
                        <hr>
                        <label>Blend: </label>
                        <input type="radio" name="group2" value="5"> 5
                        <input type="radio" name="group2" value="4"> 4
                        <input type="radio" name="group2" value="3"> 3
                        <input type="radio" name="group2" value="2"> 2
                        <input type="radio" name="group2" value="1"> 1
                        <hr>
                        <label>Warp: </label>
                        <input type="radio" name="group3" value="5"> 5
                        <input type="radio" name="group3" value="4"> 4
                        <input type="radio" name="group3" value="3"> 3
                        <input type="radio" name="group3" value="2"> 2
                        <input type="radio" name="group3" value="1"> 1
                        <hr>
                        <label>Overall: </label>
                        <input type="radio" name="group4" value="5"> 5
                        <input type="radio" name="group4" value="4"> 4
                        <input type="radio" name="group4" value="3"> 3
                        <input type="radio" name="group4" value="2"> 2
                        <input type="radio" name="group4" value="1"> 1
                <hr>
                <input type="submit" id="submit" name="submit" value="Submit" class="button">
 </form>

【问题讨论】:

  • 在你的 ajax 成功中使用 window.location.href = "index1.php";
  • 在你的 ajax 成功时做一个重定向
  • 似乎有一个答案,如果这个答案解决了您的问题,您能否通过单击答案旁边的绿色复选标记将其标记为已接受?它帮助社区知道这个问题已经得到解决。谢谢!

标签: php jquery ajax forms


【解决方案1】:

ajax成功后需要更改位置:

$.ajax({
    type: "POST",
    url: "ajaxsubmit.php",
    data: dataString,
    cache: false,
    success: function(result){
        alert(result);
        window.location = '/index1.php';
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-14
    • 2013-08-07
    • 1970-01-01
    • 2014-10-08
    • 2015-06-30
    • 2018-03-09
    • 2013-01-14
    • 2011-06-17
    相关资源
    最近更新 更多