Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > XMLHttpRequest:send not setting QUERY_STRING

Reply
Thread Tools

XMLHttpRequest:send not setting QUERY_STRING

 
 
keith.schincke@gmail.com
Guest
Posts: n/a
 
      08-12-2006
I know I must be missing something basic. I am developing of Firefox
1.5 and am trying to to send a basic QUERY_STRING to a test CGI that
will print the data back to the brower:

I can print my query string with an alert() right before the
request.send(queryString). An examination of the cgi enviroment and
tcpdump does not show QUERY_STRING being set.

Is there some I uncrossed or T on dotted?

Below is my javascript is mostly ripped from the Ajax Hacks book:

Thanks for any help.

Keith

var request;
var queryString = new
String("name=value&anothername=othervalue&so=on");

function sendData(){
url="http://www.exampe.edu/cgi-bin/printenv.cgi";
httpRequest("POST",url,false);
}

function httpRequest(reqType,url,asynch){
//Mozilla-based browsers
if(window.XMLHttpRequest){
request = new XMLHttpRequest();
} else if (window.ActiveXObject){
request=new ActiveXObject("Msxml2.XMLHTTP");
if (! request){
request=new ActiveXObject("Microsoft.XMLHTTP");
}
}
//the request could still be null if neither ActiveXObject
//initializations succeeded
if(request){
initReq(reqType,url,asynch);
} else {
alert("Your browser does not permit the use of all "+
"of this application's features!");}
}

function initReq(reqType,url,bool){
/* Specify the function that will handle the HTTP response */
request.onreadystatechange=handleJson;
request.open(reqType,url,bool);
request.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded" ) ;
alert( "Sending: " + queryString ) ;
request.send(queryString);

if(request.readyState==4)
{
alert("Text from Server : "+request.responseText);
}
}

 
Reply With Quote
 
 
 
 
BinnyVA
Guest
Posts: n/a
 
      08-12-2006
> I can print my query string with an alert() right before the
> request.send(queryString). An examination of the cgi enviroment and
> tcpdump does not show QUERY_STRING being set.


> var request;
> var queryString = new
> String("name=value&anothername=othervalue&so=on");
>
> function sendData(){
> url="http://www.exampe.edu/cgi-bin/printenv.cgi";
> httpRequest("POST",url,false);
> }
>
> function httpRequest(reqType,url,asynch){
> //Mozilla-based browsers
> if(window.XMLHttpRequest){
> request = new XMLHttpRequest();
> } else if (window.ActiveXObject){
> request=new ActiveXObject("Msxml2.XMLHTTP");
> if (! request){
> request=new ActiveXObject("Microsoft.XMLHTTP");
> }
> }
> //the request could still be null if neither ActiveXObject
> //initializations succeeded
> if(request){
> initReq(reqType,url,asynch);
> } else {
> alert("Your browser does not permit the use of all "+
> "of this application's features!");}
> }
>
> function initReq(reqType,url,bool){
> /* Specify the function that will handle the HTTP response */
> request.onreadystatechange=handleJson;
> request.open(reqType,url,bool);
> request.setRequestHeader("Content-Type",
> "application/x-www-form-urlencoded" ) ;
> alert( "Sending: " + queryString ) ;
> request.send(queryString);
>
> if(request.readyState==4)
> {
> alert("Text from Server : "+request.responseText);
> }
> }


By trial and error I fixed the problem by doing this...

var queryString = "name=value&anothername=othervalue&so=on";

instead of

var queryString = new
String("name=value&anothername=othervalue&so=on");

And commenting out the following line in the initReq()

//request.onreadystatechange=handleJson;


I have no idea why this is so. I usually use an external function like
'handleJson' that will be called when the ready state changes. I had no
idea that you could get the data in the same function. Am I missing
something here?

Another alternative is you could use the GET method.

----------------
var request;
var queryString = "name=value&anothername=othervalue&so=on";

function sendData(){
url="http://www.exampe.edu/cgi-bin/printenv.cgi";
httpRequest("GET",url+"?"+queryString,false); //GET Instead of POST
- and - queryString is appended to the url
}

function httpRequest(reqType,url,asynch){
/*
...
same
...
*/
}

function initReq(reqType,url,bool){
request.open(reqType,url,bool);
alert( "Sending: " + queryString ) ;
request.send(null);//Null value is send - not the queryString
if(request.readyState==4)
{
alert("How in the world? : "+request.responseText); //Still no
idea how this works.
}
}
----------------

Please not that I have tested this script only on Firefox 1.5 on Linux
- if it breaks on others, sorry. I kinda expect it to beak on IE - but
I cannot test it - as I am on linux.

Reference
Using POST method in XMLHTTPRequest(Ajax) -
http://www.openjs.com/articles/ajax_...using_post.php

--
Binny V A
http://binnyva.blogspot.com/

 
Reply With Quote
 
 
 
 
jake
Guest
Posts: n/a
 
      08-12-2006
Hey BinnyVA. Funny seeing you here. I emailed you once about your
Sudoku app which I put on my website (nonexistent). I was trying to
remember your web address just the other day, and then I saw your
username on this post. What a coincidence.

Well thats all, LOL. I never post in this group, I'm just a lurker.

BinnyVA wrote:
> > I can print my query string with an alert() right before the
> > request.send(queryString). An examination of the cgi enviroment and
> > tcpdump does not show QUERY_STRING being set.

>
> > var request;
> > var queryString = new
> > String("name=value&anothername=othervalue&so=on");
> >
> > function sendData(){
> > url="http://www.exampe.edu/cgi-bin/printenv.cgi";
> > httpRequest("POST",url,false);
> > }
> >
> > function httpRequest(reqType,url,asynch){
> > //Mozilla-based browsers
> > if(window.XMLHttpRequest){
> > request = new XMLHttpRequest();
> > } else if (window.ActiveXObject){
> > request=new ActiveXObject("Msxml2.XMLHTTP");
> > if (! request){
> > request=new ActiveXObject("Microsoft.XMLHTTP");
> > }
> > }
> > //the request could still be null if neither ActiveXObject
> > //initializations succeeded
> > if(request){
> > initReq(reqType,url,asynch);
> > } else {
> > alert("Your browser does not permit the use of all "+
> > "of this application's features!");}
> > }
> >
> > function initReq(reqType,url,bool){
> > /* Specify the function that will handle the HTTP response */
> > request.onreadystatechange=handleJson;
> > request.open(reqType,url,bool);
> > request.setRequestHeader("Content-Type",
> > "application/x-www-form-urlencoded" ) ;
> > alert( "Sending: " + queryString ) ;
> > request.send(queryString);
> >
> > if(request.readyState==4)
> > {
> > alert("Text from Server : "+request.responseText);
> > }
> > }

>
> By trial and error I fixed the problem by doing this...
>
> var queryString = "name=value&anothername=othervalue&so=on";
>
> instead of
>
> var queryString = new
> String("name=value&anothername=othervalue&so=on");
>
> And commenting out the following line in the initReq()
>
> //request.onreadystatechange=handleJson;
>
>
> I have no idea why this is so. I usually use an external function like
> 'handleJson' that will be called when the ready state changes. I had no
> idea that you could get the data in the same function. Am I missing
> something here?
>
> Another alternative is you could use the GET method.
>
> ----------------
> var request;
> var queryString = "name=value&anothername=othervalue&so=on";
>
> function sendData(){
> url="http://www.exampe.edu/cgi-bin/printenv.cgi";
> httpRequest("GET",url+"?"+queryString,false); //GET Instead of POST
> - and - queryString is appended to the url
> }
>
> function httpRequest(reqType,url,asynch){
> /*
> ...
> same
> ...
> */
> }
>
> function initReq(reqType,url,bool){
> request.open(reqType,url,bool);
> alert( "Sending: " + queryString ) ;
> request.send(null);//Null value is send - not the queryString
> if(request.readyState==4)
> {
> alert("How in the world? : "+request.responseText); //Still no
> idea how this works.
> }
> }
> ----------------
>
> Please not that I have tested this script only on Firefox 1.5 on Linux
> - if it breaks on others, sorry. I kinda expect it to beak on IE - but
> I cannot test it - as I am on linux.
>
> Reference
> Using POST method in XMLHTTPRequest(Ajax) -
> http://www.openjs.com/articles/ajax_...using_post.php
>
> --
> Binny V A
> http://binnyva.blogspot.com/


 
Reply With Quote
 
jmdeschamps@gmail.com
Guest
Posts: n/a
 
      08-24-2006

BinnyVA a écrit :

> > I can print my query string with an alert() right before the
> > request.send(queryString). An examination of the cgi enviroment and
> > tcpdump does not show QUERY_STRING being set.

>
> > var request;
> > var queryString = new
> > String("name=value&anothername=othervalue&so=on");
> >
> > function sendData(){
> > url="http://www.exampe.edu/cgi-bin/printenv.cgi";
> > httpRequest("POST",url,false);
> > }
> >
> > function httpRequest(reqType,url,asynch){
> > //Mozilla-based browsers
> > if(window.XMLHttpRequest){
> > request = new XMLHttpRequest();
> > } else if (window.ActiveXObject){
> > request=new ActiveXObject("Msxml2.XMLHTTP");
> > if (! request){
> > request=new ActiveXObject("Microsoft.XMLHTTP");
> > }
> > }
> > //the request could still be null if neither ActiveXObject
> > //initializations succeeded
> > if(request){
> > initReq(reqType,url,asynch);
> > } else {
> > alert("Your browser does not permit the use of all "+
> > "of this application's features!");}
> > }
> >
> > function initReq(reqType,url,bool){
> > /* Specify the function that will handle the HTTP response */
> > request.onreadystatechange=handleJson;
> > request.open(reqType,url,bool);
> > request.setRequestHeader("Content-Type",
> > "application/x-www-form-urlencoded" ) ;
> > alert( "Sending: " + queryString ) ;
> > request.send(queryString);
> >
> > if(request.readyState==4)
> > {
> > alert("Text from Server : "+request.responseText);
> > }
> > }

>
> By trial and error I fixed the problem by doing this...
>
> var queryString = "name=value&anothername=othervalue&so=on";
>
> instead of
>
> var queryString = new
> String("name=value&anothername=othervalue&so=on");
>
> And commenting out the following line in the initReq()
>
> //request.onreadystatechange=handleJson;
>
>
> I have no idea why this is so. I usually use an external function like
> 'handleJson' that will be called when the ready state changes. I had no
> idea that you could get the data in the same function. Am I missing
> something here?
>
> Another alternative is you could use the GET method.
>
> ----------------
> var request;
> var queryString = "name=value&anothername=othervalue&so=on";
>
> function sendData(){
> url="http://www.exampe.edu/cgi-bin/printenv.cgi";
> httpRequest("GET",url+"?"+queryString,false); //GET Instead of POST
> - and - queryString is appended to the url
> }
>
> function httpRequest(reqType,url,asynch){
> /*
> ...
> same
> ...
> */
> }
>
> function initReq(reqType,url,bool){
> request.open(reqType,url,bool);
> alert( "Sending: " + queryString ) ;
> request.send(null);//Null value is send - not the queryString
> if(request.readyState==4)
> {
> alert("How in the world? : "+request.responseText); //Still no
> idea how this works.
> }
> }
> ----------------
>
> Please not that I have tested this script only on Firefox 1.5 on Linux
> - if it breaks on others, sorry. I kinda expect it to beak on IE - but
> I cannot test it - as I am on linux.
>


Concatenating the url of the open method like so
'script.cgi?dataname=somedata', works in IE, Firefox, Opera BUT no
accented characters.

the send method work for IE, including accented characters, but not the
others...

> Reference
> Using POST method in XMLHTTPRequest(Ajax) -
> http://www.openjs.com/articles/ajax_...using_post.php
>
> --
> Binny V A
> http://binnyva.blogspot.com/


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
$_SERVER['QUERY_STRING'] Hj Ka Ruby 1 07-18-2008 10:45 PM
Running a perl script from an ASP page to include QUERY_STRING benwylie ASP General 4 10-19-2006 08:19 AM
to get ENV['QUERY_STRING'] instead of cgi, fcgi.. any ideas? Arie Kusuma Atmaja Ruby 0 07-21-2006 09:09 AM
Seems like the cgi module does not read the QUERY_STRING whenMETHOD is POST Quentin Crain Python 1 06-25-2004 11:24 PM
query_string <base> JS Gilbert Saint-Flour Javascript 3 05-18-2004 09:46 PM



Advertisments