Link to home
Start Free TrialLog in
Avatar of Johny Bravo
Johny Bravo

asked on

Get querystring in Javascript

Hi Experts,
I am creating Google MAP APi application.I am creating an xml file shipmentstat.xml.Now suppose userid is 4,I am passing this userid as querystring and creating the xml file as ShipmaentStat4.xml.
It wors fine.
Now In javascript I need to fetch that paricular file which ShipmaentStat4.xml which will depend on it's querystring.
How to do this?
Avatar of sunithnair
sunithnair

ASKER CERTIFIED SOLUTION
Avatar of third
third
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think the author meant server-side ASP.net JavaScript, which I am not familiar with.
But if the author meant client-side, then you would just need to use something like +/userid=(\d+)/.exec(location.search)[1] to get the number.
Avatar of Johny Bravo

ASKER

I am having some problem...

I need to access the url in following code where I am fetching XML.

 <script type="text/javascript">
     
 
      //adding to the table
          var xmlDoc=null;
                if (window.ActiveXObject)
                {// code for IE
                xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
                }
                else if (document.implementation.createDocument)
                {// code for Mozilla, Firefox, Opera, etc.
                xmlDoc=document.implementation.createDocument("","",null);
                }
                else
                {
                alert('Your browser cannot handle this script');
                }
                if (xmlDoc!=null)
                {
                xmlDoc.async=false;
                //xmlDoc.load("//192.168.1.110/MapView/ShipmentStat.xml");
                
                
                xmlDoc.load("ShipmentStat"+key[1]+".xml");
 
                document.write("<table border='1'style='width: 1300px' cellpadding='0'  cellspacing='0'>");
 
                var x=xmlDoc.getElementsByTagName("_x0040_Shipments");
                 document.write("<tr style='height=20px' >");
                document.write("<td width ='190px'>");
                document.write(
                //x[i].getElementsByTagName("Status")[0].childNodes[0].nodeValue);
                '<b> Status <b/>');
                document.write("</td>");
                 
                document.write("<td width ='180px'>");
                document.write(
                //x[i].getElementsByTagName("Status")[0].childNodes[0].nodeValue);
                '<b> Carrier  <b/>');
                document.write("</td>");
                
                
                document.write("<td width ='303px'>");
                document.write(
                //x[i].getElementsByTagName("Status")[0].childNodes[0].nodeValue);
                '<b> Origin Address <b/>');
                 document.write("</td>");
                
                document.write("<td width ='303px'>");
                document.write(
                //x[i].getElementsByTagName("Status")[0].childNodes[0].nodeValue);
                '<b> Destination Address <b/>');
                document.write("</td>");
                
                document.write("<td width ='120px'>");
                document.write(
                //x[i].getElementsByTagName("Status")[0].childNodes[0].nodeValue);
                '<b> Pick-Up Date/Time <b/>');
                document.write("</td>");
                
                document.write("<td width ='120px'>");
                document.write(
                //x[i].getElementsByTagName("Status")[0].childNodes[0].nodeValue);
                '<b> Delivery Date/Time <b/>');
                document.write("</td>");
                
                document.write("<td width ='50px'>");
                document.write(
                //x[i].getElementsByTagName("Status")[0].childNodes[0].nodeValue);
                '<b> Equipment <b/>');
                document.write("</td>");
                
                               
                for (i=0;i<x.length;i++)
                { 
                //document.write("<tr id='" + i + "' onclick='trClick(this);'  onmouseover='mover(this);'  onmouseout='mout(this);'>");
                
                document.write("<tr style='height=20px' onMouseOut=\"this.className='normal'\"  onmouseover=\"this.className='highlight'\"  id='" + i + "'  onclick='trClick(this);'>"); 
                
                //document.write("<tr>");
                
                document.write("<td width ='190px' height='20px' style='background-color: " + x[i].getAttribute("Color") + "'    >");
                document.write(
                //x[i].getElementsByTagName("Status")[0].childNodes[0].nodeValue);
                x[i].getAttribute("Status"));
                document.write("</td>");
 
                document.write("<td width ='180px'>");
                document.write(
                x[i].getAttribute("Carrier"));
                document.write("</td>");
                                
                 document.write("<td width ='303px'>");
                document.write(
                x[i].getAttribute("Origin_x0020_Address"));
                document.write("</td>");
                                
                 document.write("<td width ='303px'>");
                document.write(
                x[i].getAttribute("Destination_x0020_Address"));
                document.write("</td>");
                                 
                   document.write("<td width ='120px'>");
                document.write(
                x[i].getAttribute("Pickup_x0020_Date_x002F_Time"));
                document.write("</td>");
               
                   document.write("<td width ='120px'>");
                document.write(
                x[i].getAttribute("Delivery_x0020_Date_x002F_Time"));
                document.write("</td>");
                               
                   document.write("<td width ='50px'>");
                document.write(
                x[i].getAttribute("Equipment"));
                document.write("</td>");
                document.write("</tr>");
                }
                document.write("</table>");
                }
                //end adding table
                
                
               
 
                </script>
                

Open in new window

should it not be like this
 <script type="text/javascript">
     
 
      //adding to the table
          var xmlDoc=null;
                if (window.ActiveXObject)
                {// code for IE
                xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
                }
                else if (document.implementation.createDocument)
                {// code for Mozilla, Firefox, Opera, etc.
                xmlDoc=document.implementation.createDocument("","",null);
                }
                else
                {
                alert('Your browser cannot handle this script');
                }
                if (xmlDoc!=null)
                {
                xmlDoc.async=false;
                //xmlDoc.load("//192.168.1.110/MapView/ShipmentStat.xml");
                
                
                xmlDoc.load("http://192.168.1.110/MapView/ShipmentStat"+key[1]+".xml");
 
                document.write("<table border='1'style='width: 1300px' cellpadding='0'  cellspacing='0'>");
 
                var x=xmlDoc.getElementsByTagName("_x0040_Shipments");
                 document.write("<tr style='height=20px' >");
                document.write("<td width ='190px'>");
                document.write(
                //x[i].getElementsByTagName("Status")[0].childNodes[0].nodeValue);
                '<b> Status <b/>');
                document.write("</td>");
                 
                document.write("<td width ='180px'>");
                document.write(
                //x[i].getElementsByTagName("Status")[0].childNodes[0].nodeValue);
                '<b> Carrier  <b/>');
                document.write("</td>");
                
                
                document.write("<td width ='303px'>");
                document.write(
                //x[i].getElementsByTagName("Status")[0].childNodes[0].nodeValue);
                '<b> Origin Address <b/>');
                 document.write("</td>");
                
                document.write("<td width ='303px'>");
                document.write(
                //x[i].getElementsByTagName("Status")[0].childNodes[0].nodeValue);
                '<b> Destination Address <b/>');
                document.write("</td>");
                
                document.write("<td width ='120px'>");
                document.write(
                //x[i].getElementsByTagName("Status")[0].childNodes[0].nodeValue);
                '<b> Pick-Up Date/Time <b/>');
                document.write("</td>");
                
                document.write("<td width ='120px'>");
                document.write(
                //x[i].getElementsByTagName("Status")[0].childNodes[0].nodeValue);
                '<b> Delivery Date/Time <b/>');
                document.write("</td>");
                
                document.write("<td width ='50px'>");
                document.write(
                //x[i].getElementsByTagName("Status")[0].childNodes[0].nodeValue);
                '<b> Equipment <b/>');
                document.write("</td>");
                
                               
                for (i=0;i<x.length;i++)
                { 
                //document.write("<tr id='" + i + "' onclick='trClick(this);'  onmouseover='mover(this);'  onmouseout='mout(this);'>");
                
                document.write("<tr style='height=20px' onMouseOut=\"this.className='normal'\"  onmouseover=\"this.className='highlight'\"  id='" + i + "'  onclick='trClick(this);'>"); 
                
                //document.write("<tr>");
                
                document.write("<td width ='190px' height='20px' style='background-color: " + x[i].getAttribute("Color") + "'    >");
                document.write(
                //x[i].getElementsByTagName("Status")[0].childNodes[0].nodeValue);
                x[i].getAttribute("Status"));
                document.write("</td>");
 
                document.write("<td width ='180px'>");
                document.write(
                x[i].getAttribute("Carrier"));
                document.write("</td>");
                                
                 document.write("<td width ='303px'>");
                document.write(
                x[i].getAttribute("Origin_x0020_Address"));
                document.write("</td>");
                                
                 document.write("<td width ='303px'>");
                document.write(
                x[i].getAttribute("Destination_x0020_Address"));
                document.write("</td>");
                                 
                   document.write("<td width ='120px'>");
                document.write(
                x[i].getAttribute("Pickup_x0020_Date_x002F_Time"));
                document.write("</td>");
               
                   document.write("<td width ='120px'>");
                document.write(
                x[i].getAttribute("Delivery_x0020_Date_x002F_Time"));
                document.write("</td>");
                               
                   document.write("<td width ='50px'>");
                document.write(
                x[i].getAttribute("Equipment"));
                document.write("</td>");
                document.write("</tr>");
                }
                document.write("</table>");
                }
                //end adding table
                
                
               
 
                </script>
                

Open in new window

I am wondering the same.
When I am creating XML file in code behind,I need to specify the full path
but in javascript without giving the path //192.168.1.110/MapView/ I am able to access that XML.
Why is it so?