Why href does not work with this function

Hi all, how are you?

I’ve a problem with this ajax function, the url doesn’t actualize. I want to see the hash in url, but with the function it’s not possible. Why?

The code I use in php is:


<br><a href="#nosotros" onClick="FAjax('nosotros.php' ,'capaContenedora','','get'); return false"><b>nosotros</b></a>

With this, I’d like to see on my website: http://www.mywebsite.com/#nosotros

And the function is:

function FAjax (url,capa,valores,metodo)
{
   var ajax=creaAjax();
   var capaContenedora = document.getElementById(capa);
   			
		ajax.open ('GET', url, true);
		ajax.onreadystatechange = function() {
			 if (ajax.readyState==1) {
					 capaContenedora.innerHTML="<img src=imagenes/cargando.gif>";
			 }
			 else if (ajax.readyState==4){
				if(ajax.status==200){ 
					 document.getElementById(capa).innerHTML=ajax.responseText; 
				}
				else if(ajax.status==404)
					 {
	
						 capaContenedora.innerHTML = "La direccion existe";
					 }
					 else
					 {
						 capaContenedora.innerHTML = "Error: ".ajax.status;
					 }
			}
		}
		ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		ajax.send(null);
		return
}

TY so much! :sick:

Hi!

I’ve this part finished! I divided the hash:

var jash = window.location.hash;
var gash = jash.substring(1);
	
splitter = gash.split('?');
archivo = splitter[0];
restoant = splitter[1];

And then, when I wanna load the page:

$("#capaContenedora").load(archivo, restoant);

If I don’t split the archive part and all attributes or variables it doesn’t work correctly. Now it works.

Thanks all by your help!

TY so much whisher, I think that it’s something similar I need… I’ll continue, and when I have the correct code I’ll put here!

TY!

Hi, problem solved. If I delete the @ it works correctly!

TY!

Hi whisher, TY a lot, all problems about this solved!

Now I 've a nother one. The hash I’m passing is like this:

#archive.php?var1=res1&var2=res2

I do all splits correctly, and I obtain all variables correctly renamed as I want, including the archive where we need to call ‘archive.php’ with:

$(“#capaContenedora”).load(archivo);

But, in this archive.php that I normally collect all variables with $_GET is not working collecting the variables from hash. Is the method I’m using correct?

Thank you in advance, and sorry by my english not at all right :rolleyes:

OMG, now I understand. Thank you so much Alex.

I’m following you now in twitter! @carlossaez

TY so much.

Return false disables the navigation to a particular link in order to run the script, thereby you’re going to encounter the issue of no hash in the address bar, a better method would be to examine the hash using “var hash = location.hash.substr(1);” (in your JavaScript file) to get the hash value when it changes and then do whatever you need as and when the hash matches the value you want. Much less obtrusive and it should do the job perfectly! :slight_smile:

Not too sure what you are playing around :slight_smile:
but try to send data to the php script


$("#objectID").load("test.php", { 'var1':res1 } );

You can’t retrieve hash server side.

Hi all another time :rolleyes:

I’ve a doubt now collecting the hash. I use in function hash.js this code:

$(document).ready(function(){
    //obtain the hash
   var jash = window.location.hash;
    // if it is valid
   if(jash.length > 1){
      // if it exists, we look for the title attribute
      var href = $("a[@href="+jash+"]").attr("title");
      // we load the page
      $("#capaContenedora").load(href);
   }

    
});

This line is not working I think, because I’m placing some alerts and the variable href doesn’t exist: var href = $(“a[@href=”+jash"]").attr(“title”);

Is this correct?? -> $(“a[@href=”+jash+“]”) <-

Thank you very much in advance. :blush:

Hi,
Take a look here
http://www.learningjquery.com/2007/10/improved-animated-scrolling-script-for-same-page-links
to retrieve the hash.

Bye.