First, thank you very much for the explanation. I sense that what you wrote (about 'post') is fundamental in understanding how to work better with web application. But I don't understand all these concepts. I will have to study. Thank you!
>The behavior depends whether you use a 'regular' post or an 'AJAX' (aka XMLHTTP request, XHR, etc.) post.
>
>(1) a regular post sends the values within the containing form ... /form to the server, and displays whatever server response:
>
>HTML
>
>
><form name="myForm" action="myForm.xxx">
><input type="text" name="myText" value = "yy">
><input type="submit" name="mySubmit">
></form>
>
>
>JS using jQuery (would be possible, though longer, without)
>
>
>jQuery('form[name="myForm"]').submit(); // selector for an element having a given attribute - see http://www.w3.org/TR/css3-selectors/ -- you could also use an ID
>
>
>This will send myText= "yy" to the URL "myForm.xxx".
>When response arrives, browser will replace all the above HTML by whatever response myForm.xxx has built based on myText= "yy".
>
>(2) using AJAX, some JavaScript (eg. within jQuery) has to collect the values within the containing form /form, build the HTTP request message with the proper encoding, send to the server and deal with the response. In short everything takes place behind the scene:
>HTML: same as above
>JS using jQuery (would be possible, though longer, without)
>
>
>$.post('myForm.xxx', $('form[name="myForm"]').serialize(), function(response){process response});
>
>
>This code will also send myText= "yy" to the URL "myForm.xxx";
>However, when the response built by myForm.xxx arrives, the function passed as 3rd parameter executes with this response as parameter.
>This function is sole responsible for changing the HTML page as appropriate; eg display a success message to the user.
>Nothing else changes in the HTML page 'naturally'.
>
>The reason why I explain those mechanism is: while (1) is the natural ('traditional') HTTP behavior, (2) is closer to a desktop application such as VFP: when a user event occurs in VFP, the code in the corresponding event method executes and is sole responsible for changing anything in the display.
>
>We dealt with that 15 years ago, and this was one of the very fundamental reasons why we came up with FoxInCloud using AJAX posts only.
>
>>Do I understand that if you add an element (e.g. div of id="test") in the script section of the page, and then the page is sent back from the server (posted back) this element no longer exists? That is, I cannot use this element in the IF statement of the javascript?
>>
>>For example, I want to call a certain method of the page but only One Time. And I was doing the following (which does not seem to work):
>>
>>
>> if ($('#Test').length==0) {
>> // div of ID Test does not exist.
>> // create this div
>> var $div = $('<div />').appendTo('body');
>> $div.attr('id', 'Test');
>> // Call button click method.
>> document.getElementById("btnTest").click();
>> }
>>
>>
>>The above seem to go into an endless loop.
>>
>>Any suggestions? TIA
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham