0

I'm using an ajax form to send post data to a php file. And want to reload the current page with variable response from that php. Actually I need to update only the url in address bar after success response. This is my code:

    type: 'POST',
    success: function(data){
        var data;
        if(data && data != 'error') {
            window.history.pushState("string", "Title", "article.php?do=$_GET[do]&token='+data+'");
        }else{
            $('#saveStts').html('error');
        }

My response variable from php is a time stamp like 1433428606. I need this number to reload a page with the full url is : www.test.com/admin/article.php?do=edit&token=1433428606. I tried but always reload with data instead of timestamp from a server. Please be advice.

Wilf
  • 2,297
  • 5
  • 38
  • 82

1 Answers1

0

This state push can be done in Chrome, Safari, FF4+, and IE10+.

The way you're currently doing looks right, are you having any troubles?

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

There's a very good response on the topic here: Updating address bar with new URL without hash or reloading the page

Community
  • 1
  • 1
Raphael Costa
  • 86
  • 1
  • 3
  • The thing is I can't get the response code from php file to reload the url. The response code is a time stamp `1433418642` and I need this number to reload the page with. The full url is `http://www.test.com/admin/edit.php?id=xxx&token=1433418642` – Wilf Jun 04 '15 at 16:10
  • Why are you re-initiating/overwriting the variable data? You can remove "var data;". If you still have an issue after removing that line, explode data, like console.log(data) and see what is getting returned. – Raphael Costa Jun 04 '15 at 16:30