Getting started with jquery 4: jquery processes returned data in XML format

Source: Internet
Author: User

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/>} 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.