Home > Ajax, JavaScript > JavaScript – go back, go back detection, ajax go back

JavaScript – go back, go back detection, ajax go back

Completely bogus when something was saying back you cant, Here how i did, using 100% ajax boot methods.

Difficulties was:

a) visitors comes to localhost/index.php

b) visitors is routed to localhost/index.php?g=1

c) visitors is now completely ajax module, onclick menus he gets contents.

d) visitors need to go back, when apply go back it goes to point A). localhost/index.php

Note: This is not the common ajax we use, b is itself a ajax for whole index.php?g=1 , c is the sub ajax sections

Solved as:

folder tree:

= shamun
– js/jquery.history.js
– js/global.js
– include/home.php
– include/menu_button_3_contents.php

– index.php

1. This plugin is used, i didn’t write it, because of time limitation, many thanks to mikage sawatari. (i will modify on this plugin for my own uses).

Download: http://dpaste.de/hSgZ/

2. A fix ajax binding function, where you can load ajax sub pages. In my case it was two route, so i splited the href link to two different location. in other case it may contain only one:

function myAjaxReturn(url,_datastr){
return $.ajax({
type    : “POST”,
url     : url,
data    : _datastr,
async : false,
success : function(msg){
// this is the sub page url, “include/page33.php”;
url = url.split(“/”);
if ( url[1]==’main.php’){
$save  = $(‘#jQuery_history’);  // to avoid error
$(document.body).empty().prepend($save).append(msg);
}else{
$(‘#alltable’).empty().append(msg);
}
}
}).responseText;
}

3. Now you apply on click buttons or div or td or anything:

// 1. Basic ajax would be like this but to have history, we will not use those methods.

// $(‘#alltable’).html(”).load(‘include/link_mijnaccount.php’);

$(“#home”).click ( function () {

// So this is the ajax method that basically we use, without history management

$.historyLoad(‘include/home.php’);

// just to avoid wrong window.location.href return false; });

// 1. Basic ajax would be like this but to have history, we will not use those methods.

// $(‘#alltable’).html(”).load(‘include/link_mijnaccount.php’);

$(“#menu_button_3”).click ( function () {

// So this is the ajax method that basically we use, without history management

$.historyLoad(‘include/menu_button_3_contents.php’);

// just to avoid wrong window.location.href

return false;

});


Advertisements
Categories: Ajax, JavaScript Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: