in this example Program , I will use $. ajax () method, using $. the get () method is acceptable, but I think $. ajax () is better. Code is easier to understand and not complex.
// Define the user name verification method <br/> function verify () {<br/> // first, test the button on the page and press, you can call this method <br/> // use the alert method of JavaScript to display a prompt box <br/> // alert ("the button is clicked !!! "); <Br/> // 1. obtain the content in the text box <br/> // document. getelementbyid ("username"); DOM method <br/> // jquery node search method. You can find a node by adding the value of ID in the parameter. <Br/> // The jquery method returns jquery objects. You can continue to execute other jquery methods above. <br/> var jqueryobj = $ ("# username "); <br/> // obtain the node value <br/> var username = jqueryobj. val (); <br/> // alert (username); <br/> // 2. send the data in the text box to the server segment's servelt <br/> // JavaScript, a simple object definition method <br/> var OBJ = {name: "123 ", age: 20 }; <br/> // encapsulate the GET request using the XMLHTTPRequest object of jquery <br/> $. ajax ({<br/> type: "Post", // HTTP Request Method <br/> URL: "ajaxxmlserver", // server segment URL <br/> data: "Name =" + username, // data sent to the server segment <br/> datatype: "XML", // notify jquery of the returned data format <br/> success: callback // defines the callback function that is called when the interaction is completed and the server correctly returns data <br/>}); <br/>}
Callback function:
// Callback function <br/> function callback (data) {<br/> // alert ("the data in the server segment is returned !! "); <Br/> // 3. receive data returned by the server <br/> // You Need to parse the data in the DOM object <br/> // first, you need to convert the DOM object to the jquery object <br /> var jqueryobj = $ (data ); <br/> // obtain the message node <br/> var message = jqueryobj. children (); <br/> // get text content <br/> var text = message. text (); <br/> // 4. dynamically display the data returned from the server segment on the page <br/> // find the node that saves the result information <br/> var resultobj = $ ("# result "); <br/> // dynamically change the content of the DIV node on the page <br/> resultobj.html (text); <br/> alert (""); <br/>}