By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,590 Members | 663 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,590 IT Pros & Developers. It's quick & easy.

AJAX POST problems on Firefox

P: n/a
Hi all,

I am having some odd problems with AJAX on Firefox (1.5). When I use
GET as the request method everything works ok, but when I do a POST the
remote function doesn't get the parameters I am passing to it.
Everything works fine on IE 6. Here's a couple samples of what I am
doing:

// using GET
url = 'http://www.myserver.com/cgi-bin/funct?key1=value1&key2=value2'

ajaxRequest.onreadystatechange = callback;
ajaxRequest.open('GET', url, true);
ajaxRequest.send(null);

// using POST
url = 'http://www.myserver.com/cgi-bin/funct'
request = 'key1=value1&key2=value2'

ajaxRequest.onreadystatechange = callback;
ajaxRequest.open('POST', url, true);
ajaxRequest.send(request);

Do you guys see a problem?

Thanks,
Danny

Feb 2 '06 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Danny wrote:
I am having some odd problems with AJAX on Firefox (1.5). When I use
GET as the request method everything works ok, but when I do a POST the
remote function doesn't get the parameters I am passing to it.
Everything works fine on IE 6. Here's a couple samples of what I am
doing:

// using GET
url = 'http://www.myserver.com/cgi-bin/funct?key1=value1&key2=value2'
Declare all your variables using the `var' keyword always. And almost all
statements, including simple assignments, should be delimited by a trailing
semicolon in order to avoid side effects with automatic semicolon insertion
by the script engine.
ajaxRequest.onreadystatechange = callback;
ajaxRequest.open('GET', url, true);
open() clears all event listeners with the XMLHttpRequest XUL object
implemented in Gecko-based browsers; probably this is also what the
original IXMLHTTPRequest interface does. Reverse the order of
those two statements.
ajaxRequest.send(null);

// using POST
url = 'http://www.myserver.com/cgi-bin/funct'
request = 'key1=value1&key2=value2'

ajaxRequest.onreadystatechange = callback;
ajaxRequest.open('POST', url, true);
Same here.
ajaxRequest.send(request);

Do you guys see a problem?


Yes, see above.
HTH

PointedEars
Feb 2 '06 #2

P: n/a
VK

Danny wrote:
Hi all,

I am having some odd problems with AJAX on Firefox (1.5). When I use
GET as the request method everything works ok, but when I do a POST the
remote function doesn't get the parameters I am passing to it.
Everything works fine on IE 6. Here's a couple samples of what I am
doing:

// using GET
url = 'http://www.myserver.com/cgi-bin/funct?key1=value1&key2=value2'

ajaxRequest.onreadystatechange = callback;
ajaxRequest.open('GET', url, true);
ajaxRequest.send(null);

// using POST
url = 'http://www.myserver.com/cgi-bin/funct'
request = 'key1=value1&key2=value2'

ajaxRequest.onreadystatechange = callback;
ajaxRequest.open('POST', url, true);
ajaxRequest.send(request);

Do you guys see a problem?


To POST data you have to set the request header to
'application/x-www-form-urlencoded'
ajaxRequest.setRequestHeader('Content-type',
'application/x-www-form-urlencoded');

Be aware that some older implementations of Safari and Opera are bad
with setRequestHeader, so there you are limited by GET only. Not really
practically important (screw on them and let them finally update). Just
let you know that POST may fail for some rare visitors.

Feb 2 '06 #3

P: n/a
Thomas 'PointedEars' Lahn said the following on 2/2/2006 5:14 PM:
Danny wrote:
I am having some odd problems with AJAX on Firefox (1.5). When I use
GET as the request method everything works ok, but when I do a POST the
remote function doesn't get the parameters I am passing to it.
Everything works fine on IE 6. Here's a couple samples of what I am
doing:

// using GET
url = 'http://www.myserver.com/cgi-bin/funct?key1=value1&key2=value2'
Declare all your variables using the `var' keyword always.


No. Declare all your variables using the 'var' keyword *unless* you
understand the ramifications of not doing so. In the global scope, there
is no difference in the following two script blocks:

<script type="text/javascript">
myVariable = 'This is a global variable'
</script>

<script type="text/javascript">
var myVariable = 'This is a global variable'
</script>

Note: There are no trailing semi-colons. I very seldom add them in my
own code. I usually add them to Usenet code so I don't have to listen to
arguments such as this one about adding them. The script engine will add
them where they should be and won't add them where they shouldn't be.
And almost all statements, including simple assignments, should be delimited
by a trailing semicolon in order to avoid side effects with automatic semicolon
insertion by the script engine.


Unless you know where to and where not to put them, you are safer *not*
putting them in. There was a post just yesterday with a for statement
with a trailing semicolon that changed the meaning of the code.

for (var i=0;i<someArray.length;i++);

Or close to it. And that trailing semi-colon changed the meaning of the
code.

The last time I corrected you about this I asked for an example of code
where the lack of a trailing semi-colon *breaks* the code and adding it
back caused the error to cease.

function myFunction(){;

Syntax Error!!!

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 3 '06 #4

P: n/a
Randy Webb wrote:
Thomas 'PointedEars' Lahn said the following on 2/2/2006 5:14 PM:
Danny wrote:
I am having some odd problems with AJAX on Firefox (1.5). When I use
GET as the request method everything works ok, but when I do a POST the
remote function doesn't get the parameters I am passing to it.
Everything works fine on IE 6. Here's a couple samples of what I am
doing:

// using GET
url = 'http://www.myserver.com/cgi-bin/funct?key1=value1&key2=value2'
Declare all your variables using the `var' keyword always.


No. Declare all your variables using the 'var' keyword *unless* you
understand the ramifications of not doing so. In the global scope, there
is no difference in the following two script blocks:

<script type="text/javascript">
myVariable = 'This is a global variable'
</script>


Wrong. It has been proven before already that there can be an object in
the scope chain, before the global object, that is a host object. This
is the case in JScript as used in IE: if there is an HTML element with
name or ID of `myVariable' and `myVariable' has not been declared before,
this assignment results in an error everywhere in the code because this
host object implements the simple assignment operation differently than
specified in ECMAScript Edition 3 (which is nevertheless ECMAScript
compliant behavior.) Declaring this identifier as a variable identifier
avoids this runtime error because the scope chain is not used (global
declaration) or used differently (local declaration) then.

Therefore, variables should be declared _always_ (or they may be no
variables at all.)
And almost all statements, including simple assignments, should be
delimited by a trailing semicolon in order to avoid side effects with
automatic semicolon insertion by the script engine.


Unless you know where to and where not to put them, you are safer not
putting them in.


Wrong.
There was a post just yesterday with a for statement
with a trailing semicolon that changed the meaning of the code.

for (var i=0;i<someArray.length;i++);


Which part of "almost" is unclear to you?
PointedEars
Feb 3 '06 #5

P: n/a
Randy Webb wrote:
Thomas 'PointedEars' Lahn said the following on 2/2/2006 5:14 PM:
Danny wrote:
I am having some odd problems with AJAX on Firefox (1.5). When I use
GET as the request method everything works ok, but when I do a POST the
remote function doesn't get the parameters I am passing to it.
Everything works fine on IE 6. Here's a couple samples of what I am
doing:

// using GET
url = 'http://www.myserver.com/cgi-bin/funct?key1=value1&key2=value2'
Declare all your variables using the `var' keyword always.


No. Declare all your variables using the 'var' keyword *unless* you
understand the ramifications of not doing so. In the global scope, there
is no difference in the following two script blocks:

<script type="text/javascript">
myVariable = 'This is a global variable'
</script>


Wrong. It has been proven before already that there can be an object in
the scope chain, before the global object, that is a host object. This
is the case in JScript as used in IE: if there is an HTML element with
name or ID of `myVariable' and `myVariable' has not been declared before,
this assignment results in an error everywhere in the code because this
host object implements the simple assignment operation differently than
specified in ECMAScript Edition 3 (which is nevertheless ECMAScript
compliant behavior.) Declaring this identifier as a variable identifier
avoids this runtime error because the scope chain is not used then for
the initialization.

Therefore, variables should be declared _always_ (or they may be no
variables at all.)
And almost all statements, including simple assignments, should be
delimited by a trailing semicolon in order to avoid side effects with
automatic semicolon insertion by the script engine.


Unless you know where to and where not to put them, you are safer not
putting them in.


Wrong.
There was a post just yesterday with a for statement
with a trailing semicolon that changed the meaning of the code.

for (var i=0;i<someArray.length;i++);


Which part of "almost" is unclear to you?
PointedEars
Feb 3 '06 #6

P: n/a
Thomas 'PointedEars' Lahn said the following on 2/3/2006 8:50 AM:
Randy Webb wrote:
Thomas 'PointedEars' Lahn said the following on 2/2/2006 5:14 PM:
Danny wrote:
I am having some odd problems with AJAX on Firefox (1.5). When I use
GET as the request method everything works ok, but when I do a POST the
remote function doesn't get the parameters I am passing to it.
Everything works fine on IE 6. Here's a couple samples of what I am
doing:

// using GET
url = 'http://www.myserver.com/cgi-bin/funct?key1=value1&key2=value2'
Declare all your variables using the `var' keyword always. No. Declare all your variables using the 'var' keyword *unless* you
understand the ramifications of not doing so. In the global scope, there
is no difference in the following two script blocks:

<script type="text/javascript">
myVariable = 'This is a global variable'
</script>


Wrong.


Wrong Thomas.

Let me quote what you ignored ok? Make sure you read it properly this time:

IN THE GLOBAL SCOPE.

Get it now? In the GLOBAL scope they are equivalent.
It has been proven before already that there can be an object in
the scope chain, before the global object, that is a host object.
Irrelevant to what I said.
This is the case in JScript as used in IE: if there is an HTML element with
name or ID of `myVariable' and `myVariable' has not been declared before,
this assignment results in an error everywhere in the code because this
host object implements the simple assignment operation differently than
specified in ECMAScript Edition 3 (which is nevertheless ECMAScript
compliant behavior.)
Yoohoo. Read what I wrote Thomas : "Unless you understand the
ramifications of not doing so".

Sidenote: I don't give a crap what ECMA says. I care what the browsers do.
Declaring this identifier as a variable identifier avoids this runtime
error because the scope chain is not used (global declaration) or used
differently (local declaration) then.
And if you are stupid enough to name your variables the same as your
ID's, then you deserve what you get. Using IE as a defense is no defense
at all.

And, please oh please name just one browser on the Web where the above
script won't create a Global Variable. Just one.

But, just in case you missed it again, let me repeat what I said one
more time:

In the GLOBAL SCOPE, there is no difference in the two script blocks.
Declare all your variables using the 'var' keyword *unless* you
understand the ramifications of not doing so.

Do you fail to understand what I wrote? You must.
Therefore, variables should be declared _always_ (or they may be no
variables at all.)


Again, you didn't understand what I wrote. Try it again.

And almost all statements, including simple assignments, should be
delimited by a trailing semicolon in order to avoid side effects with
automatic semicolon insertion by the script engine.

Unless you know where to and where not to put them, you are safer not
putting them in.


Wrong.


Once again, you are wrong Thomas.
There was a post just yesterday with a for statement
with a trailing semicolon that changed the meaning of the code.

for (var i=0;i<someArray.length;i++);


Which part of "almost" is unclear to you?


Let me repeat for you, again, what I wrote and I will endeavor to
explain it to you since you either ignored it or didn't comprehend it:

<quote>
Unless you know where to and where not to put them, you are safer not
putting them in.
</quote>

Now, you get an example that maybe will shed some light on what you are
missing.

<script type="text/javascript">
myNonVarDeclaredVariable = 0
for (var i=0;i<100;i++)
{
myNonVarDeclaredVariable++
}
alert(myNonVarDeclaredVariable)
</script>

Thats perfectly valid Script. It will do what it was designed to do.
Increment a variable. It does that. Now, someone comes along and reads
PointedEars saying "End your statements with ;" and they add semi-colons
to the ends of all the lines and get this:

<script type="text/javascript">
myNonVarDeclaredVariable = 0;
for (var i=0;i<100;i++);
{;
myNonVarDeclaredVariable++;
};
alert(myNonVarDeclaredVariable);
</script>

Now, by not understanding when to, and not to, add semi-colons the
unknowing just changed what the code does and introduced syntax errors.

So, "Unless you know where to and where not to put them, you are safer
not putting them in".

The JS Engine will parse the script block and insert them where they
belong and will not insert them where they do not belong.

When writing, it is better to be clear and concise. Your statement left
a lot of ambiguity, mine did not. Learn the difference.

Then, take your corrections like a man.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 3 '06 #7

P: n/a
Randy Webb wrote:

[Readded previously snipped code]
Thomas 'PointedEars' Lahn said the following on 2/3/2006 8:50 AM:
Randy Webb wrote:
Thomas 'PointedEars' Lahn said the following on 2/2/2006 5:14 PM:
Danny wrote:
> I am having some odd problems with AJAX on Firefox (1.5). When I use
> GET as the request method everything works ok, but when I do a POST
> the remote function doesn't get the parameters I am passing to it.
> Everything works fine on IE 6. Here's a couple samples of what I am
> doing:
>
> // using GET
> url = 'http://www.myserver.com/cgi-bin/funct?key1=value1&key2=value2'
Declare all your variables using the `var' keyword always.
No. Declare all your variables using the 'var' keyword *unless* you
understand the ramifications of not doing so. In the global scope, there
is no difference in the following two script blocks:

<script type="text/javascript">
myVariable = 'This is a global variable'
</script>

<script type="text/javascript">
var myVariable = 'This is a global variable'
</script>
Wrong.


Wrong Thomas.


No, I am correct.
Let me quote what you ignored ok? Make sure you read it properly this
time:

IN THE GLOBAL SCOPE.

Get it now? In the GLOBAL scope they are equivalent.
No, they are _not_, in /any/ scope. In the first case the scope chain is
used; in the second case it is not.
It has been proven before already that there can be an object in
the scope chain, before the global object, that is a host object.


Irrelevant to what I said.


It is very relevant to what you said. You can seldom know, with Closed
Source you can never know, the inner workings of the implementation used,
including the scope chain. It is error-prone and eventually incompetent
to ignore that.
This is the case in JScript as used in IE: if there is an HTML element
with name or ID of `myVariable' and `myVariable' has not been declared
before, this assignment results in an error everywhere in the code
because this host object implements the simple assignment operation
differently than specified in ECMAScript Edition 3 (which is nevertheless
ECMAScript compliant behavior.)


Yoohoo. Read what I wrote Thomas : "Unless you understand the
ramifications of not doing so".


You yourself did not understand the ramifications of doing so (yet?).
Sidenote: I don't give a crap what ECMA says.
Then you are a fool because you are dealing with conforming implementations
of ECMAScript (ECMA-262, ISO/IEC 16262). Not only because I (and a
considerable number of other participants of this newsgroup) say so, but
because the creators of the respective script engines themselves say so.
I care what the browsers do.


Then read the previous discussion on the subject as I already suggested. It
contains an example that _breaks_ in IE if the identifier is not a declared
variable. It does _not_ break if it is.

BTW: You replied to a posting canceled (on Google Groups) and superseded
with news:20****************@PointedEars.de already.
PointedEars
Feb 3 '06 #8

P: n/a
Thomas 'PointedEars' Lahn said the following on 2/3/2006 11:54 AM:
Randy Webb wrote:

[Readded previously snipped code]
Thomas 'PointedEars' Lahn said the following on 2/3/2006 8:50 AM:
Randy Webb wrote:
Thomas 'PointedEars' Lahn said the following on 2/2/2006 5:14 PM:
> Danny wrote:
>> I am having some odd problems with AJAX on Firefox (1.5). When I use
>> GET as the request method everything works ok, but when I do a POST
>> the remote function doesn't get the parameters I am passing to it.
>> Everything works fine on IE 6. Here's a couple samples of what I am
>> doing:
>>
>> // using GET
>> url = 'http://www.myserver.com/cgi-bin/funct?key1=value1&key2=value2'
> Declare all your variables using the `var' keyword always.
No. Declare all your variables using the 'var' keyword *unless* you
understand the ramifications of not doing so. In the global scope, there
is no difference in the following two script blocks:

<script type="text/javascript">
myVariable = 'This is a global variable'
</script>

<script type="text/javascript">
var myVariable = 'This is a global variable'
</script>
Wrong. Wrong Thomas.


No, I am correct.


That is your opinion, and you are entitled to it. Your opinion is based
on ignoring *all* of what I wrote. But, that is your choice. Should
people use the var keyword? Sure. Can they do without it? Yes, but, only
if they understand the ramifications of not using it. The ramifications
part is what you are ignoring.

Let me quote what you ignored ok? Make sure you read it properly this
time:

IN THE GLOBAL SCOPE.

Get it now? In the GLOBAL scope they are equivalent.
No, they are _not_, in /any/ scope. In the first case the scope chain is
used; in the second case it is not.


You still didn't get it. If both of those script blocks are executed in
the global scope then they are both global variables. Show me some code
that shows otherwise though.
It has been proven before already that there can be an object in
the scope chain, before the global object, that is a host object.

Irrelevant to what I said.


It is very relevant to what you said.


No it's not. If you understand the ramifications, and the behavior you
get is what you are after, then you can do what you want. If you don't
understand, then take the safe path and use the var keyword.
You can seldom know, with Closed
Source you can never know, the inner workings of the implementation used,
including the scope chain. It is error-prone and eventually incompetent
to ignore that.
Again, only if you don't understand the ramifications of not using the
var keyword.

If I repeat that enough, will you finally get it?

This is the case in JScript as used in IE: if there is an HTML element
with name or ID of `myVariable' and `myVariable' has not been declared
before, this assignment results in an error everywhere in the code
because this host object implements the simple assignment operation
differently than specified in ECMAScript Edition 3 (which is nevertheless
ECMAScript compliant behavior.)

Yoohoo. Read what I wrote Thomas : "Unless you understand the
ramifications of not doing so".


You yourself did not understand the ramifications of doing so (yet?).


You underestimate my understanding. I am well aware of what the
ramifications are.
Sidenote: I don't give a crap what ECMA says.


Then you are a fool because you are dealing with conforming implementations
of ECMAScript (ECMA-262, ISO/IEC 16262).


I am a fool for not caring what a document says but rather I worry more
about what the browsers do? I can write cross-browser scripts and never
even know what ECMA says. You can not write cross-browser scripts based
solely on knowing what ECMA says. You *must* know the browser behavior.
And given a choice between MSDN and the Gecko docs versus ECMA's
documentation, you can have ECMA.

And to prove that point, it only takes using toFixed in IE and you will
soon find out that it's more important to know what the browser is going
to do than what ECMA says it should do because IE5.0 in its default
install configuration will fail with toFixed because its buggy.
Not only because I (and a considerable number of other participants of
this newsgroup) say so, but because the creators of the respective script
engines themselves say so.
ECMA is an attempt to standardize what was already in place. Not the
other way around.

Theory: ECMA should be all you need to know.
Reality: ECMA doesn't mean a hill of beans.

If it did, then the language would be ECMAScript and not J(ava)script.

I care what the browsers do.


Then read the previous discussion on the subject as I already suggested. It
contains an example that _breaks_ in IE if the identifier is not a declared
variable. It does _not_ break if it is.


And I already said that if you are stupid enough to fall into that trap
then you deserve what you get. That is one of the ramifications I was
referring to that you keep ignoring.

But, which is it? Are you going to stand behind ECMA or the browser's
behavior? You can't have it both ways.
BTW: You replied to a posting canceled (on Google Groups) and superseded
with news:20****************@PointedEars.de already.


BTW: It was not cancelled or I wouldn't have seen it. And you are
assuming that just because you went to Google and asked for the message
to be cancelled that it did indeed get cancelled - it didn't.

But, since you mention the double post, you should fix your newsreader -
it double posts quite a bit.

What? No more about the semi-colons?
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 5 '06 #9

P: n/a
JRS: In article <w5******************************@comcast.com>, dated
Sun, 5 Feb 2006 08:48:24 remote, seen in news:comp.lang.javascript,
Randy Webb <Hi************@aol.com> posted :

But, since you mention the double post, you should fix your newsreader -
it double posts quite a bit.


That may be because he uses supersedes, presumably in an endeavour to
cover up careless hasty posting.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Feb 6 '06 #10

P: n/a
Dr John Stockton said the following on 2/6/2006 10:16 AM:
JRS: In article <w5******************************@comcast.com>, dated
Sun, 5 Feb 2006 08:48:24 remote, seen in news:comp.lang.javascript,
Randy Webb <Hi************@aol.com> posted :
But, since you mention the double post, you should fix your newsreader -
it double posts quite a bit.


That may be because he uses supersedes, presumably in an endeavour to
cover up careless hasty posting.


Don't let him know that not all News Servers honor the superseded
Header. If you do, he will go on for weeks about RFC's and such and end
up saying it is my fault I saw his double posts. <g>

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 7 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.