Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   XMLHttpRequest:send not setting QUERY_STRING (http://www.velocityreviews.com/forums/t926360-xmlhttprequest-send-not-setting-query_string.html)

keith.schincke@gmail.com 08-12-2006 03:41 AM

XMLHttpRequest:send not setting QUERY_STRING
 
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);
}
}


BinnyVA 08-12-2006 04:47 AM

Re: XMLHttpRequest:send not setting QUERY_STRING
 
> 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/


jake 08-12-2006 11:12 PM

Re: XMLHttpRequest:send not setting QUERY_STRING
 
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/



jmdeschamps@gmail.com 08-24-2006 03:26 AM

Re: XMLHttpRequest:send not setting QUERY_STRING
 

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/




All times are GMT. The time now is 08:47 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.