Question

I want after Ajax success function I could return to the previous page.

<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.");
                           }
                    });
            }
      });

But it won't work.


UPDATE

it works after I try to remove dialog('close'):

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

but, I need to double click on submit button. why?

Was it helpful?

Solution

it works..

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

just change -1 into -2.

OTHER TIPS

Suggestions:

  • I don't find any use of AJAX here because of async:false
  • Call PHP page and using header redirect to your desired page
  • Debug your code by console.log once ajax call succeeds
  • try window.history.back() instead of history.back()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top