1

I have here a code that saves the data of the main.php contents

When viewing a certain list, I use a URL parameter for the php to generate.

ex: main.php?v=323&p=1

Now the problem is, I want it to be remove when I save the contents after I made changes. Here is the code I use for saving the form contents.

$.ajax({
  type:'POST',
  url:'/AJAXsave.php',
  cache:false,
  async:true,
  global:false,
  dataType:"html",
  data:$('#form1contents').serialize(),
  timeout:10000
});

I want those parameters to be removed (?v=323&p=1) upon the completion of the ajax post.

0

3 Answers 3

1

Just add the "complete" or the "success" function to your Ajax call:

$.ajax({
  type:'POST',
  url:'/AJAXsave.php',
  cache:false,
  async:true,
  global:false,
  dataType:"html",
  data:$('#form1contents').serialize(),
  timeout:10000,
  complete: function (xhr, status)
  {
      if(status == 'success')
          location.href = 'main.php';
  }
});

According to the jQuery API: complete - A function to be called when the request finishes (after success and error callbacks are executed). The function gets passed two arguments: The jqXHR (in jQuery 1.4.x, XMLHTTPRequest) object and a string categorizing the status of the request ("success", "notmodified","error","timeout","abort", or"parsererror"). As of jQuery 1.5, thecomplete setting can accept an array of functions. Each function will be called in turn. This is an Ajax Event. jQuery Ajax

Sign up to request clarification or add additional context in comments.

Comments

1

You can uses this, but only in Chrome, Safari, FF4+, and IE10pp4+!

window.history.pushState("object or string", "Title", "/new-url");

Reference MDN

2 Comments

Too bad it doesn't work on IE8. I need to support 3 major browsers.
So you just need to reload the page with the URL you need. I was thought that you didn't want reload the page.
0

I just wanted to remove URL parameter after getting request. This worked for me.

window.history.pushState("object or string", "Title", "/new-url");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.