1

I'm doing an AJAX request and changing my URL, but when I go back on browser, my url changes to the old one but my content does not.

Here is my code:

$('.link').on('click', function (e) {
    e.preventDefault();

    History.pushState('data', '', this.href);

    $('#content').load(this.href);

});

I'm using Jquery and History.js.

Edit:

To be more clearer:

I do the ajax, my server returns to me HTML that I replace my page content with it. I use History.pushState to change my url but when I hit the browser back button, It does not go back, only my url changes.

William Weckl
  • 2,435
  • 4
  • 26
  • 43
  • Maybe [this SO](http://stackoverflow.com/questions/11146397/jquery-history-js-back-button-not-working) question/answer helps. – AWolf Nov 19 '14 at 19:18
  • Already tried that. Did not work for me. Maybe I'm doing something wrong. – William Weckl Nov 19 '14 at 19:20
  • Ah OK, I've tried to do a jsfiddle with jQuery mobile but it supports history out of the box. See the following [jsFiddle](http://jsfiddle.net/ydysxyx1/2/). What library/framework do you use for routing? – AWolf Nov 19 '14 at 19:38
  • I'm using nothing for routing. It's just a website in php with jquery and History.js. Did not understand your example very well. What have Jquery mobile to do with that? And the back I'm referring is the back button of the browser, when I manipulate my URL with History.pushState I'm not able to go back. – William Weckl Nov 19 '14 at 19:44
  • OK, I've tought you're doing routing in js. jQuery mobile have nothing to do with it. Just as example. It's not clear what you'd like to do. Yes, in my example the history routing is working with the browser back button. – AWolf Nov 19 '14 at 19:53
  • Hmmm. Now I saw. I'm sorry but JS is not my strong. How could you do that without a single JS line? – William Weckl Nov 19 '14 at 19:55
  • Tried to remove JqueryMobile and found what was doing the magic. Can I do that without JqueryMobile? – William Weckl Nov 19 '14 at 19:58
  • Maybe this helps. [go-back-via-js-and-php](http://perishablepress.com/go-back-via-javascript-and-php/) – AWolf Nov 19 '14 at 20:14
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/65238/discussion-between-william-weckl-and-awolf). – William Weckl Nov 19 '14 at 20:17

0 Answers0