...

create dynamic url for the navigate buttons

kamkam
10-27-2007, 08:00 AM
Hi,

I am struggling for creating dynamic url for the navigates buttons, it is same as this
forum's navigate buttons (< 1 2 3 >).

i got a list buttons which are button 1 ,button 2 and button2.
when i click one of the buttons, i want to have a url with "www.mypage.com/javascript/1"
or "www.mypage.com/php/2".

the prblem i have, is that
when i do the second click on one of buttons, the browser give me the following url, and bring a 404 error massage.

http://www.mywebsite.com/%3Chtml%3E%3Cbody%3E%20%20This%20is%20the%20404%20error%20webpage.%20%3Cbr%3E%20The%20file%20you%20a re%20looking%20for,%20do%20not%20exist.%3C/body%3E%3C/html%3E/3/

This is the 404 error webpage.

but i do the first click on the one of the buttons, it bring out the right url i want as following:

http://www.mywebsite.com/javascript/3

the problem always happen after the first click.

Could anyone help me, please.


my mod_rewrite rule in .htaccess file

RewriteEngine On
RewriteRule ^javascript/([0-9]+)/$ /index.php?page=$1 [L]



index.php

<html>
<body>
<input type="button" id="b1" name="bb1" value="1" onClick="cButtons('b1')">
<input type="button" id="b2" name="bb2" value="2" onClick="cButtons('b2')">
<input type="button" id="b3" name="bb3" value="3" onClick="cButtons('b3')">


<script type="text/javascript">
function cButtons(buttonN){
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
var rV;
rV=xmlHttp.responseText;
nextT(rV,buttonN);
}
}
xmlHttp.open("GET","cateV.php",true);
xmlHttp.send(null);

}


function nextT(rV, bN){
var bOValue, bValue;
bOValue=document.getElementById(bN).value;
bValue=bOValue.toString();

window.location.href = "/" +rV + "/" + bValue +"/";

}
}
</script>
</body>
</html>


/////////////////////////////////////////////
cateV.php

<?php

$test="javascript";
echo $test;
?>


note for i have tested in the function nextT(rV, bN).

i have done 2 test for the values of rV.
1)i use the "window.location.href = "/javascript/" + bValue +"/"; " instead of the
"window.location.href = "/" +rV + "/" + bValue +"/";", then the browser create the
right dynamic url for me, like "http://www.mywebsite.com/javascript/3" or
"http://www.mywebsite.com/javascript/1" , it does not matter how many times i click
on the buttons.
2) i put a line of code of the " alert(" the value of rV is " + rV);"
infront of the "window.location.href = "/" +rV + "/" + bValue +"/";",
it pop up a window with the value of the javascript, it does not matter
how many times i click on.
it is very sure that the rV value already come into the function nextT(rV,bN),
but it is strange that it doesn't create dynammic url when i click the second
click on the one of the buttons.

A1ien51
10-27-2007, 01:49 PM
So if you unescpe your URL thatis all jumped it is:

"http://www.mywebsite.com/<html><body> This is the 404 error webpage. <br> The file you are looking for, do not exist.</body></html>/3/"

Problem is your script is calling the ajax page:

http://www.mywebsite.com/javascript/1/cateV.php

Set the URL to be absolute so it will call the correct file

http://www.mywebsite.com/cateV.php

Eric

kamkam
10-28-2007, 05:44 AM
Thanks a lot, i have solved the problem already.

i get rid off the ajax code and pass php varibal to the javascript function.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum