JavaScript 函数 Submit() 函数和 send() 函数之间有什么区别?
我一直在通过一本书学习 JavaScript。当我在处理有关客户端-服务器站点通信的代码时,我想使用下面的代码执行 POST 请求(使用 IE ActiveX 对象 XMLHttpRequest):
<script type="text/javascript">
var oRequest = HTTPRequestUtil.getXmlHttp();
var sRequestType = "post";
var sURLofRequest = "MyPage.aspx";
var bAsnychronously = false;
oRequest.open(sRequestType, sURLofRequest, bAsnychronously);
oRequest.send(null);
alert ('Status is '+oRequest.status+' ('+oRequest.statusText+')');
alert ('Response text is '+oRequest.responseText);
</script>
我在 MyPage.aspx 页面的 PAGE_load 事件处理程序上设置了断点。 。
我期望当上面的 HttpRequest 发生时,执行会停止在该位置(它是在 html 按钮单击时调用的) 并且在我设置断点的 Page_Load 方法处没有停止
所以,现在我无法理解使用 POST 请求类型调用 .send() 函数和调用时的 Submit() 函数之间的区别,
如果您能解释一下,我将不胜感激。主要区别
谢谢!
I have been studying JavaScript from one book. Once I was playing with the codes concerning the client-server site communication, I wanted to do a POST request with the code below (which uses IE ActiveX object XMLHttpRequest):
<script type="text/javascript">
var oRequest = HTTPRequestUtil.getXmlHttp();
var sRequestType = "post";
var sURLofRequest = "MyPage.aspx";
var bAsnychronously = false;
oRequest.open(sRequestType, sURLofRequest, bAsnychronously);
oRequest.send(null);
alert ('Status is '+oRequest.status+' ('+oRequest.statusText+')');
alert ('Response text is '+oRequest.responseText);
</script>
I have breakpoint on the PAGE_load eventhandler of the MyPage.aspx" page. I was expecting the execution will stop at that place when this HttpRequest occurs above. (It is called on a html button click).
The thing is, the request is done, the responseText is obtained (which was the xml content of the page) and no stop at the Page_Load method where I have put a breakpoint.
So, now I cannot understand the difference between calling .send() function with POST request type and submit() function on the call.
I would appreciate if you can explain the main differences briefly.
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不同之处在于,使用
send
会将数据发送回 JavaScript 调用例程,而无需重新加载页面,但在表单上调用submit
会将表单提交到服务器,然后重新加载来自服务器的结果,就好像用户单击了表单的提交按钮一样。“发送”就是所谓的 Ajax,例如,Stackoverflow 投票按钮就是通过它来将选票发送回服务器而无需重新加载整个页面的。
The difference is that using
send
will send the data back to the JavaScript calling routine without reloading the page, but callingsubmit
on a form submits the form to the server and then reloads the results from the server as if the user had clicked on the submit button of the form.The "send" is what is known as Ajax, and it is, for example, how the Stackoverflow voting buttons work to send the votes back to the server without reloading the entire page.