473,513 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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);
}
}

Aug 12 '06 #1
3 8162
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/

Aug 12 '06 #2
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/
Aug 12 '06 #3

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/
Aug 24 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
10249
by: Jarson | last post by:
My JavaScript is trying to POST data to a CGI script (Perl) using XMLHttpRequest. My CGI server gets different data from IE than Mozilla Firefox. // For Mozilla, req = new XMLHttpRequest(); //...
10
14061
by: Matt Kruse | last post by:
I'm aware of the circular reference memory leak problem with IE/closures. I'm not sure exactly how to resolve it in this situation. Also, Firefox appears to grow its memory size with the same code....
3
2342
by: robocoder | last post by:
I came across something I'm unfamiliar with -- there's an added check for window.location.href.indexOf("http")==-1 to see if the XMLHttpRequest send() completed, i.e., if...
7
12668
by: TJO | last post by:
I am executing the following JavaScript to initiation a post to another page on my site. I need to retreive the string data being sent in the ..send() method. However, I cannot locate the string...
11
22604
by: afrinspray | last post by:
I get this error everytime I finish an AJAX post with http.send(null): Error: uncaught exception: " nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: :: getReplyWindow :: line...
1
4505
by: edai | last post by:
I am trying to find some sample code which uses the send() method of xmlhttprequest. most of the examples on the web use send(NULL) and encode the data in open(get,url?name=value) format. If i am...
1
5286
by: Tarik Monem | last post by:
OK, I'm pretty sure this cannot work because I'm trying to use JavaScript (client-side) to write to an xml file (which is server-side) using XMLHttpRequest. Can I use PHP do what I'm trying to do?...
2
1621
by: zdrakec | last post by:
The relevent code (it's a basic example): var XMLHTTP = GetXMLHTTP(); if(XMLHTTP != null) { XMLHTTP.open("GET","default.aspx"); XMLHTTP.onreadystatechanged = stateChanged; XMLHTTP.send(null);...
0
7265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7388
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7545
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7111
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7539
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5095
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4751
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
461
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.