Firefox上的AJAX POST问题 [英] AJAX POST problems on Firefox

查看:55
本文介绍了Firefox上的AJAX POST问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我在Firefox(1.5)上遇到一些奇怪的AJAX问题。当我使用

GET作为请求方法时,一切正常,但是当我执行POST时,

远程函数没有得到我传递给它的参数。

在IE 6上一切正常。这里有几个我喜欢的样品:
做什么:


//使用获取

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


ajaxRequest.onreadystatechange = callback;

ajaxRequest.open(''GET'',url,true);

ajaxRequest.send(null);


//使用POST

url ='''http://www.myserver.com/cgi-bin/funct''

request =' 'key1 = value1& key2 = value2''


ajaxRequest.onreadystatechange = callback;

ajaxRequest.open(''POST'',url,true) ;

ajaxRequest.send(请求);


你们有没有看到问题?


谢谢,

Danny

解决案
丹尼写道:
我有在Firefox(1.5)的一些奇问题AJAX。当我使用G / GET作为请求方法时,一切正常,但是当我进行POST时,
远程函数没有得到我传递给它的参数。
一切正常IE 6.这里有几个我正在做的事情的样本:

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


始终使用`var''关键字声明所有变量。几乎所有的

语句,包括简单的赋值,都应该用一个尾随的

分号分隔,以避免自动分号插入的副作用

通过脚本引擎。

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


open()使用XMLHttpRequest XUL对象清除所有事件监听器

在基于Gecko的浏览器中实现;可能这也是

原始IXMLHTTPRequest接口的作用。颠倒

这两个陈述的顺序。

ajaxRequest.send(null);

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

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


同样在这里。

ajaxRequest.send(请求);

你们有没有看到问题?




是的,见上文。

HTH


PointedEars




Danny写道:

大家好,

我在Firefox(1.5)上遇到了一些奇怪的AJAX问题。当我使用G / GET作为请求方法时,一切正常,但是当我进行POST时,
远程函数没有得到我传递给它的参数。
一切正常IE 6.这里有几个我正在做的事情的样本:

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

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

//使用POST
url ='''http://www.myserver.com/cgi-bin/funct''
请求=''key1 = value1& key2 = value2''

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

你们有没有看到问题?




要POST数据,你必须将请求标题设置为

''application / x-www-form-urlencoded''

ajaxRequest.setReq uestHeader(''Content-type'',

''application / x-www-form-urlencoded'');


请注意一些较旧的Safari和Opera的实现很糟糕

with setRequestHeader,所以你只受限于GET。不是真的很重要(紧紧抓住它们,让它们最终更新)。只是

让你知道POST可能会失败一些罕见的访客。


Thomas''PointedEars''Lahn说以下在2006年2月2日下午5:14:

Danny写道:

我在Firefox(1.5)上遇到了一些奇怪的AJAX问题。当我使用G / GET作为请求方法时,一切正常,但是当我进行POST时,
远程函数没有得到我传递给它的参数。
一切正常IE 6.这里有几个我正在做的事情的样本:

//使用GET
url =''http://www.myserver.com/cgi -bin / funct?key1 = value1& key2 = value2''
始终使用`var''关键字声明所有变量。




编号声明所有变量都使用''var''关键字*除非*你

了解不这样做的后果。在全球范围内,

在以下两个脚本块中没有区别:


< script type =" text / javascript">

myVariable =''这是一个全局变量''

< / script>


< script type =" text / javascript">

var myVariable =''这是一个全局变量''

< / script>


注意:没有尾随的分号。我很少将它们添加到我的

自己的代码中。我通常将它们添加到Usenet代码中,所以我不必听取

这样的关于添加它们的参数。脚本引擎将添加

它们应该在哪里,并且不会将它们添加到它们不应该的位置。

几乎所有语句,包括简单的赋值,应该用一个尾随的分号分隔,以避免脚本引擎插入自动分号的副作用。




除非你知道哪里到哪里都不放他们,你更安全*不是*

把他们放进去。昨天有一篇文章发表了一个for语句

,后面跟着一个分号改变了代码的含义。


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


或接近它。那个尾随的分号改变了

代码的含义。


我最后一次纠正你的问题我问了一个代码示例

,缺少一个尾部分号*破坏*代码并添加它

返回导致错误停止。


function myFunction(){;


语法错误!!!

-

兰迪

comp.lang.javascript常见问题 - http://jibbering.com/faq &安培;新闻组每周

Javascript最佳实践 - http://www.JavascriptToolbox .com / bestpractices /


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

解决方案

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



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.


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/


这篇关于Firefox上的AJAX POST问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆