views:

122

answers:

1

Hi,

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!

+1  A: 

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.

Kinopiko
Thanks. The sample in here ( http://msdn.microsoft.com/en-us/library/ms535874%28VS.85%29.aspx ) is parrallel to your saying: "The 'send' is what is known as Ajax."
burak ozdogan