JavaScript 函数 Submit() 函数和 send() 函数之间有什么区别?

发布于 2024-08-10 11:24:06 字数 778 浏览 4 评论 0原文

我一直在通过一本书学习 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

守望孤独 2024-08-17 11:24:06

不同之处在于,使用 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 calling submit 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文