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();
// For IE req = new ActiveXObject("Microsoft.XMLHTTP");
req.onreadystatechange = requestHandler ; // function to handle async
response
req.open('POST', myURL, true); // use POST
req.send('foo=11&bar=22') ;
A Perl CGI script prints the parameters passed to it.
$q = new CGI ;
foreach my $param ($q->param) {
print "$param: " . $q->param($param) . "\n" ;
}
The data received by the CGI script is inconsistent, depending if the client
is IE or Mozilla (Firefox)
Server result from IE client:
foo: 11
bar: 22
Server result from Mozilla Firefox client:
POSTDATA: foo=11&bar=22
It seems that the POST data IE sends is more correct than the Mozilla data.
Is there another way to send the data in Mozilla so the CGI script will give
the same results. I could easily adjust the CGI script, but I think the
problem is at the client.
Jarson (jarson from sygration, that's a dot com company if you need to send
an email) 5 10240
On Sat, 30 Apr 2005 12:55:08 -0400, "Jarson" <ja*****@nospam.com> wrote: 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(); // For IE req = new ActiveXObject("Microsoft.XMLHTTP"); req.onreadystatechange = requestHandler ; // function to handle async response req.open('POST', myURL, true); // use POST req.send('foo=11&bar=22') ;
A Perl CGI script prints the parameters passed to it. $q = new CGI ; foreach my $param ($q->param) { print "$param: " . $q->param($param) . "\n" ; }
The data received by the CGI script is inconsistent, depending if the client is IE or Mozilla (Firefox) Server result from IE client: foo: 11 bar: 22 Server result from Mozilla Firefox client: POSTDATA: foo=11&bar=22
It seems that the POST data IE sends is more correct than the Mozilla data. Is there another way to send the data in Mozilla so the CGI script will give the same results. I could easily adjust the CGI script, but I think the problem is at the client.
Aren't you missing setting the content-type for your request, that is, using:
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
Perhaps one browser fills in the blanks whereas the other doesn't; either way
you ought to explicitly state it when POSTing data.
--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jarson wrote: 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(); // For IE req = new ActiveXObject("Microsoft.XMLHTTP"); req.onreadystatechange = requestHandler ; // function to handle async response req.open('POST', myURL, true); // use POST
First make the open call, then set the onreadystatechange handler and
then before you send the data set the HTTP request header e.g.
if (typeof req.setRequestHeader != 'undefined') {
req.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
}
req.send('foo=11&bar=22') ;
as that seems to be the content type of the data you want to post.
--
Martin Honnen http://JavaScript.FAQTs.com/
MAGIC!! Adding setRequestHeader to my JavaScript fixed it!
setRequestHeader was missing from my code and all of the documentation and
samples I've read!
Unscientific research:
Google for +XMLHttpRequest +send = 65,500 results
Google for +XMLHttpRequest +setRequestHeader = 516 results
Thanks Martin and Andy for that piece of valuable information!
Jarson
"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:42**********************@newsread2.arcor-online.net...
Jarson wrote:
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(); // For IE req = new ActiveXObject("Microsoft.XMLHTTP"); req.onreadystatechange = requestHandler ; // function to handle async response req.open('POST', myURL, true); // use POST
First make the open call, then set the onreadystatechange handler and then before you send the data set the HTTP request header e.g. if (typeof req.setRequestHeader != 'undefined') { req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); }
req.send('foo=11&bar=22') ;
as that seems to be the content type of the data you want to post.
--
Martin Honnen http://JavaScript.FAQTs.com/
Martin Honnen wrote: Jarson wrote: 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(); // For IE req = new ActiveXObject("Microsoft.XMLHTTP"); req.onreadystatechange = requestHandler ; // function to handle async response req.open('POST', myURL, true); // use POST
First make the open call, then set the onreadystatechange handler [...]
Does not make sense to me. Why?
PointedEars
Thomas 'PointedEars' Lahn <Po*********@web.de> writes: Martin Honnen wrote:
[XMLHttpRequest] First make the open call, then set the onreadystatechange handler [...]
Does not make sense to me. Why?
Why it doesn't make sense to you? Who knows :)
Anyway: The "open" call doesn't make the connection, it merely sets up
the request-object. The actual connection is created when the "send"
method is called, and the ready-state will not change until this
point. That means that it's safe to assign the handler after the call
to "open".
Some browsers will not honor event handlers set before the "open"
call, as if that call completely initializes the object.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.' This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Robin Becker |
last post by:
Is there any way to get an IFRAME to do a POST without altering the
browser window's history?
I can achieve dynamic data loading using GET via the iframe's
contentWindow.location.replace method,...
|
by: Todd |
last post by:
I have been tasked to create an app that will be run from a CD on
stand-alone machines that needs to search and retrieve data from an
XML Data Island.
The best approach that I can see to handle...
|
by: David Given |
last post by:
I have a web app, written in Javascript, that communicates to a back-end
server via XMLHttpRequest.
The logic goes:
* Login
* Perform transaction
* (delay while the user does something)
*...
|
by: knocte |
last post by:
Hello.
I have always thought that the eval() function was very flexible and
useful. If I use it, I can define functions at runtime!!
However, I have found a case where eval() does not work...
|
by: M B HONG 20 |
last post by:
Hi all -
I am developing an ASP.NET web application that requires the use of
remote calls going on behind the client's page in the browser. I
successfully got the service working via SOAP (I...
|
by: Jim Lawton |
last post by:
Hello, the following bit of (stripped down) code works fine in IE, but on Gecko
based browsers -
Firefox 1.0.7
Mozilla 1.7.12
it just hangs on the xmlhttpOpen
// IE object - works fine...
|
by: ted benedict |
last post by:
hi everybody, i hope this is the right place to discuss this weird
behaviour. i am getting dynamically generated text or xml from the
server side using xmlhttprequest. if the server side data is...
|
by: libsfan01 |
last post by:
In IE6 i get an error: "XMLHttpRequest is undefined", whereas in other
browsers (e.g. ie7) it works fine:
var get;
function getdata(region,page) {
get = new XMLHttpRequest();...
|
by: ajaxcoder |
last post by:
Hi
In my project i had a login form and i am trying to send the username and password to the server for authentication using xmlHttpRequest. Hence i am using POST request but i am unable to send...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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...
|
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
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...
| |