Im having problems loading content with ajax, the problem its that lets say that I have 2 links on my index.html, one is #page1 and the other one is #games1, well have happens is that if I click on either of them it just loads the same site, even thought both files page1.html and test1.html are different and are located in the server, please take a look at the code below which has a bit of php and ajax.I think the issue might be on line 45 and 46 on the ajax part.


var default_content="";

	$('ul li a').click(function (e){


	//filling in the default content
	default_content = $('#pageContent').html();

var lasturl="";

function checkURL(hash)
	if(!hash) hash=window.location.hash;
	if(hash != lasturl)
		// FIX - if we've used the history buttons to return to the homepage,
		// fill the pageContent with the default_content

function loadPage(url)
		type: "POST",
		url: "load_page.php",
		data: 'page='+url,
		dataType: "php",
		success: function(msg){


Recommended Answers

All 4 Replies

try returning false so that the browser does not navigate away when the link is clicked:

$('ul li a').click(function (e){

          return false;

This did not work, what happens now its that if you lick on a link than the url at the top wont change, for example it will stay as

what happens now its that if you lick on a link than the url at the top wont change

Yes, that was expected. Why is that an issue? Aren't you tracking the last hash in a variable? Meaning, everytime a link with a hash is clicked you are updating lasturl . If later on I click on a different link that has a hash, then you need to compare the hash on the "current link that was just clicked" against what you previously stored in lasturl . IF they match, then don't do an ajax request (since it is already loaded - should be the current loaded page).

Do you have Skype, I need to show you a live demo so you can see the issue

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.