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 9 of 9

Thread: urgent help

  1. #1
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    urgent help

    can any one please help me out with the code.

    I am passing an URL for ex: www.example.com?req=23&param=25

    What i need to do is I need to remove the parameters after "?" which I did using the spilt method,

    Can anyone help me out now how do I send the complete URL with the parameters as hidden.

    what I mean is..my URL should look like
    www.example.com.

    but the second part (parameter shud be hidden).

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    You mean hidden but still effective?

    You cannot do that with Javascript. As soon as you change the URL of the current page (including the removal of parameters), the page will refresh by re-requesting it from the server. The server will most certainly "miss" the parameters and will then not generate the appropriate page.

    One question: How did the parameters get there? Did they come from a previous page that sent some form data to the server using the GET method? If yes, you can switch the form method to POST (which will still send the data, but not in the URL any more). This also means that you need to change the server side script to accept POST parameters instead of GET.

  • #3
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    No I am using the Post method, this URL is getting formed using few components.
    I can provide you with the code snippet which I am using, if you can help thereafter.

    function subLink(param){
    hiddenVal = document.getElementById('GENENUM').value;

    if(param!= ""){

    var form = document.createElement("form");
    document.body.appendChild(form);
    form.setAttribute('action',action);
    form.setAttribute('method','POST');

    alert('Submittt.....');
    var hiddenObj = document.createElement("input");
    hiddenObj.type = "hidden";
    hiddenObj.id = "some id";//same which is used in form
    hiddenObj.name = "some_token";
    hiddenObj.value = hiddenVal;
    var myString = new String(document.location);
    var myArray = myString.split('?');


    form.appendChild(hiddenObj);

    form.submit();

    }

    }

  • #4
    Regular Coder
    Join Date
    Apr 2005
    Location
    Texas
    Posts
    448
    Thanks
    24
    Thanked 63 Times in 63 Posts
    continuing with your logic...

    Code:
    var myArray = myString.split('?');
    
    var myRealArray = myArray[1].split('&');
    
    var myTokens = {};
    
    for (var i=0 ; i<myRealArray.length ; ++i){
    
        var tmp = myRealArray[i].split('=');
    
        myTokens[tmp[0]] = tmp[1];
    
    }
    //now you have a myTokens object equal to {"req":"23" , "param":"25"}
    Edit:
    Huh, I did not read that question right... but if you wish to conceal your parameters, you should just use AJAX to post your form. sorry for the confusion
    Last edited by blaze4218; 03-15-2012 at 05:55 PM.
    Allwisend bin ich nicht, doch viel ist mir bewursst
    -Goethe

  • #5
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for the reply mate..

    But I need to do this with a javascript only. It is basically a URL rewriting, cant I do with making the extracted param as hidden.

    I am sorry I am newbie to Js... n dont have much command over it.

    I dont want to use anything other than JS, cant we make the parameters after ? as hidden ...and pass the same.

  • #6
    Regular Coder
    Join Date
    Apr 2005
    Location
    Texas
    Posts
    448
    Thanks
    24
    Thanked 63 Times in 63 Posts
    AJAX is javascript
    Allwisend bin ich nicht, doch viel ist mir bewursst
    -Goethe

  • Users who have thanked blaze4218 for this post:

    mayanks (03-15-2012)

  • #7
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy

    Quote Originally Posted by blaze4218 View Post
    AJAX is javascript


    Can u help me out with code...how can I do that?

  • #8
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Has anybody any solution to this?

  • #9
    New Coder
    Join Date
    Mar 2012
    Posts
    13
    Thanks
    0
    Thanked 1 Time in 1 Post
    Simple AJAX request

    Code:
    function createRequest() {
    	  try {
    	    request = new XMLHttpRequest();
    	  } catch (tryMS) {
     	    try {
    	      request = new ActiveXObject("Msxml2.XMLHTTP");
    	    } catch (otherMS) {
    	      try {
    	        request = new ActiveXObject("Microsoft.XMLHTTP");
    	      } catch (failed) {
    	        request = null;
    	      }
    	    }
    	  }	
    	  return request;
    	}
    
      function getStreets(city){	
    	  
    	  var streets = document.getElementById("streets");
    	  var ctid = document.getElementById("ctid").value;
    	  
    	  
    	  streetRequest = createRequest();
    	  if (streetRequest == null)
    		    alert("Unable to create request");
    		  else {
    			  
    		    var url= "/dripdrop/includes/myincludes/getStreets.php?city=" + city.value + "&ctid=" + ctid;
    		    streetRequest.onreadystatechange = function(){
    		    	if (streetRequest.readyState == 4)   
    	                              if (streetRequest.status == 200) { 
    
                                            streets.innerHTML = streetRequest.responseText;
    	                            }
    			}
    
    		    }
    		    streetRequest.open("GET", url, true);
    		    streetRequest.send(null);
    		  }
    	}
    in this example streetRequest.responseText is what is being returned from the server.


  •  

    Posting Permissions

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