Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Understanding javascript
Message
De
09/12/2015 03:17:47
 
 
Information générale
Forum:
Javascript
Catégorie:
JQuery
Divers
Thread ID:
01628679
Message ID:
01628710
Vues:
39
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
Thierry Nivelet
FoxinCloud
Give your VFP application a second life, web-based, in YOUR cloud
http://foxincloud.com/
Never explain, never complain (Queen Elizabeth II)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform