开发者

What is the Difference between submit() function and send() JavaScript functions?

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 sReq开发者_开发问答uestType = "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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜