0 Basic Learning AJAX AJAX Framework _ajax related

Source: Internet
Author: User

Above (0 Basic Learning Ajax Ajax Introduction and foundation) to the AJAX asynchronous request server to do a detailed introduction and basic application, you can see that some of the AJAX process is relatively unchanged. Some Ajax developers have encapsulated their process into an AJAX framework without having to write the code every time a request is sent.

This section mainly introduces the Ajaxlib and Ajaxgold two frameworks.

1.ajaxLib

Ajaxlib is a very small AJAX framework.
Use it to first introduce file usage into the page. The change frame is a framework for obtaining XML directly, and the transport function is as follows:

Loadxmldoc (Url,callback,boolean)
Where the URL is the address of the asynchronous request, callback the function name to be dispatched after the request succeeds; Boolean indicates whether to remove the space in the XML document, true to remove the space

Such as:

<input type= "button" value= "Display" onclick= "Loadxmldoc (' 1-7.aspx ', decodexml,false);"/>
The XML document returned with the Ajaxlib framework is saved in the global variable resultxml, and can be analyzed by writing a program in Decodexml, for example:

Copy Code code as follows:

function Decodexml () {
var otemp =resultxml.getelementsbytagname ("temp");
document.getElementById ("Targetid"). InnerHTML = Otemp[0].firstchild.nodevalue;
}

You can see that the code is a lot less long than before.

2. Use of Ajaxgold

Ajaxgold is another particularly useful AJAX framework.

Ajaxgold is another particularly useful AJAX framework. It has 4 functions for developers to use

Copy Code code as follows:

Getdatareturntext (Url,callback);
Getdatareturnxml (Url,callback);
Postdatareturntext (Url,data,callback);
Postdatareturnxml (Url,data,callback);

The first two are used to return text and XML for Get, followed by two functions that return text and XML using a POST request, with Postdatareturntext (Url,data,callback) as an example to illustrate

Copy Code code as follows:

<form>
<input type= "button" value= "Request Data" onclick= "Postdatareturntext (' 1-8.aspx ', ' a=2&b=3 ', display);" >
</form>
<div id= "Targetid" > Extracted data will be displayed in this </div>

The above code sends the data to the 1-8.aspx, and passes the data a=2b=3, after the server returns successfully, the dispatching function display () handles the return value.

In Ajaxgold, the return text is used as the only parameter to the callback function, so the display () function can write

Copy Code code as follows:

<script type= "Text/javascript" >
function display (text) {
document.getElementById ("Targetid"). InnerHTML = text;
}
</script>

The above is the entire content of this article, I hope you can enjoy

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.