1

我想要在Ajax success function我可以返回上一页之后。

<div id="dialog" title="Complain">
       <form id="komenform">
                <label>Model :</label>
                <input type="text" id="comodel" name="comodel"/>
                <label>Komentar :</label>
                <textarea id="comment" name="comment" rows="5" cols="20" ></textarea>
                <button id="submitcom" type="button" class="ui-state-default ui-corner-all"><span>Submit </span></button>
                <input name="action" value="inputcom" type="hidden">
       </form>
</div>

$("#komenform").validate({
        rules:{
                comodel:{
                          required:true
                          },
                comment:{
                        required:true
                        }
                }
        });

$("#submitcom").click(function() {
      if($("#komenform").valid()) {
            var params=$("#komenform").serialize();
            $.ajax({
                    type:"post",
                    url:"/QA/process2.php",
                    data:params,
                    cache :false,
                    async :false,
                    success : function() {
                           $("#comodel").val("");
                           $("#comment").val("");
                           $("#dialog").dialog('close');
                           history.back();
                           },
                    error : function() {
                           alert("Data failed to input.");
                           }
                    });
            }
      });

但它不会起作用。


更新

我尝试删除后它可以工作dialog('close')

success : function() {
       $("#comodel").val("");
       $("#comment").val("");
 //      $("#dialog").dialog('close');
       window.history.go(-1);
       return false;
       },

但是,我需要双击提交按钮。为什么?

4

2 回答 2

2

有用..

success : function() {
       $("#comodel").val("");
       $("#comment").val("");
 //      $("#dialog").dialog('close');
       window.history.go(-2);
       return false;
       },

只需更改-1-2.

于 2013-08-16T06:26:27.207 回答
1

建议:

  • 由于 async:false,我在这里没有发现任何使用 AJAX
  • 调用 PHP 页面并使用标题重定向到您想要的页面
  • ajax 调用成功后,通过 console.log 调试代码
  • 尝试 window.history.back() 而不是 history.back()
于 2013-08-15T10:03:07.237 回答