0

First thing i want to say is that i tried many codes and plugins, but nothing work for me. I am trying only to make the buttons "back" and "forward" in the browser to call again the AJAX called pages so they appear after the buttons are clicked. I hope you get that i am NOT developer :).

Please help me guys, these are days of work in this very moment...:)

The handlers:

<li><a href="#" class="ceni">примерни цени</a></li>
<li><a href="#" class="karieri">кариери</a></li> 

The javascript:

$('.ceni').click(function(){ 
    $.ajax({
        url: 'pages/ceni.php',
        success: function(response) {
            $("#pages").html(response);
        }
    });       
});   

$('.karieri').click(function(){     
    $.ajax({
        url: 'pages/karieri.php',
        success: function(response) {
            $("#pages").html(response);
        }
    });       
});
DIF
  • 2,470
  • 6
  • 35
  • 49
Bat Jeko
  • 49
  • 6
  • `I hope you get that i am NOT developer`. I am sorry to say it but Stack Overflow is for developers or for people willing to learn and become developers. If you are not a developer nor willing to learn something you might consider hiring a developer doing the job for you. – Darin Dimitrov Feb 21 '12 at 16:40
  • Have a look here: http://stackoverflow.com/questions/116446/what-is-the-best-back-button-jquery-plugin – Jinx Feb 21 '12 at 16:40
  • You might want to take a look at the jQuery history plugin: http://tkyk.github.com/jquery-history-plugin/ – itsmequinn Feb 21 '12 at 16:41
  • @DarinDimitrov I interpreted it more as an indication that we'll need to explain things we'd normally take for granted, rather than as an unwillingness to learn or do any work for themselves. I could be wrong, though. – Anthony Grist Feb 21 '12 at 16:42
  • I am learning right now and i have learned many things but not in the javascript. I am willing to create sites and have created some like this http://athome-bg.com/, but i can not call myself a developer like the people in this site i think. – Bat Jeko Feb 21 '12 at 16:52
  • syntax error in the second ajax call URL. not sure if this is relevant. – jbabey Feb 21 '12 at 17:24

2 Answers2

0

Try this:

    $('.ceni').click(function(){      

             $.ajax({
type: 'GET',
url: 'pages/ceni.php',
success: function(response) {
 $("#pages").html(response);
}
});       
});
Leo
  • 51
  • 5
0

The most common method is by using a plugin for monitoring the hashchange event and re-requesting the ajax page.

<li><a class="ceni"    href="#ceni">примерни цени</a></li>
<li><a class="karieri" href="#karieri">кариери</a></li>

Set up the hash change handlers:

jQuery(window).bind('hashchange', function() {
  var pageHash = location.hash.substr(1);
  if('ceni|karieri|'.indexOf(pageHash + '|') >= 0) {
    jQuery("#pages").load(pageHash + '.php');
  }
});

Loading content into an element via jQuery is documented at http://api.jquery.com/load/ and is fundamentally the same as using jQuery.ajax to make the request.

As an alternative, you can use the HTML5 history API documented at http://html5demos.com/history - which allows you to keep the address bar looking tidy without the hashes.

If you need to support IE7 and below, use a polyfill for the hashchange event such as http://benalman.com/projects/jquery-hashchange-plugin/

steveukx
  • 4,370
  • 19
  • 27
  • Thank you man, but your code doesnt work for me. I tried Ben Alman's plugin but but doesn't work also. I don't understant what's wrong. No matter :), Thank you. Really appreciate your help. God bless. – Bat Jeko Feb 21 '12 at 19:19
  • No trouble - what browser are you using? http://jsfiddle.net/steveukx/gU6g9/ this is a working example in Chrome – steveukx Feb 21 '12 at 19:34
  • Only pop-up appears but, i say "ok" and the previous page does not reload. – Bat Jeko Feb 22 '12 at 09:58
  • I've not put ajax into the fiddle (as it's in the example above), so the alert is for illustrative purposes... click on the links a few times and you'll see an alert for each click, then use "back" in the browser history and you'll see an alert that has been triggered because of the hashchange event – steveukx Feb 22 '12 at 17:46