问题描述
我有一种情况需要发送数据,但我不需要
响应。在我看来,XMLHTTPRequest是发送
数据的最佳方式,但我不需要从服务器回复任何响应。
基本上,我正在将js错误写入服务器端的错误日志 -
并且无需通知用户错误已被记录。
问题是我不想坐在请求打开和放大等待
作为回复,当我不需要回复时。我想我可以
服务器响应只是OK或类似的东西,但是它的确是不相关的b $ b
我在考虑只是在readystate = 1中删除请求(在那个
点,服务器端脚本应该已经执行了,对吧?),但是
我想知道是否还有其他方法可以发送..
Thanx
I have a situation where I want to send data, but I have no need for a
response. It seems to me that XMLHTTPRequest is the best way to send the
data, but I don''t need any response back from the server.
Basically, I''m writing js errors to an error log on the server side -
and there is no need to inform the user that the error has been logged.
The problem is that I don''t want to sit with the request open & waiting
for a response, when I have no need for the response. I suppose I could
have the server respond with just "OK" or something like that, but it''s
really not relevant
I was thinking of just aborting the request on readystate=1 (at that
point, the server-side script should have executed already, right?), but
I was wondering if there were any other methods to JUST send..
Thanx
推荐答案
Not一个脚本问题。请参阅HTTP规范,204 /无内容响应
Not a script question. See HTTP specs, 204 / No Content response
否,XMPHTTPRequest不是发送数据的最佳方式。特别是
,因为你不需要回复。
myVar = new Image();
myVar.src = " pathToServerSideScript.ext" + errorMessage;
然后服务器端脚本执行,没有任何响应。
这是如此广泛的问题,它在常见问题:
< URL:>
如何执行服务器端脚本?
-
兰迪
comp.lang.javascript常见问题 - &新闻组每周
Javascript最佳实践 -
No, XMPHTTPRequest is not the best way to send the data. Especially
since you don''t need the response.
myVar = new Image();
myVar.src = "pathToServerSideScript.ext?" + errorMessage;
Then the server side script executes and nothing is done with the response.
This is so widely asked that its in the FAQ:
<URL: http://jibbering.com/faq/#FAQ4_34 >
"How do I execute a server side script?"
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
不,XMPHTTPRequest不是发送数据的最佳方式。特别是
因为你不需要回复。
myVar = new Image();
myVar.src =" pathToServerSideScript.ext?" + errorMessage;
No, XMPHTTPRequest is not the best way to send the data. Especially
since you don''t need the response.
myVar = new Image();
myVar.src = "pathToServerSideScript.ext?" + errorMessage;
这个老技巧总能奏效,但这只是一个技巧,我认为XHR是正确的方式
这样做。除了查询字符串也有一个
大小限制这一事实,所以这个技巧也不是发送数据的最佳方式。
如果你不需要发送大量数据,或者如果你需要
与旧浏览器的兼容性,那么......使用查询字符串。
否则我全都是XHR \ o /,因为对我来说这显然是正确的方式,
如果回复对你没关系,甚至不会产生它!由于
你只需要检查标题(有一种方法可以在这个XHR对象上获取
标题,但我认为它不存在于IE,搜索一下
小嘿嘿)。
-
Jonas Raoni Soares Silva
这篇关于" AJAX" - 发送但不需要回复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!