Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    306
    Thanks
    24
    Thanked 0 Times in 0 Posts

    create dynamic url for the navigate buttons

    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%...%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

    PHP Code:
    <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(rVbN){
             var 
    bOValuebValue;
              
    bOValue=document.getElementById(bN).value;
              
    bValue=bOValue.toString();
              
              
    window.location.href "/" +rV "/" bValue +"/";
                  
          }
       }
    </script>
    </body>
    </html> 
    /////////////////////////////////////////////
    cateV.php

    PHP Code:
    <?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.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    So if you unescpe your URL thatis all jumped it is:

    Code:
    "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:

    Code:
    http://www.mywebsite.com/javascript/1/cateV.php
    Set the URL to be absolute so it will call the correct file

    Code:
    http://www.mywebsite.com/cateV.php
    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    Regular Coder
    Join Date
    Dec 2006
    Posts
    306
    Thanks
    24
    Thanked 0 Times in 0 Posts
    Thanks a lot, i have solved the problem already.

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •