Ajax. updater Application

Source: Internet
Author: User
Tags ruby on rails

Ajax. updater Application


Through this JS class library, AJAX technology will be easily applied
Ajax. updater Application
New Ajax. Updater ('id', "url", {options });
Id: id of the target to be updated
Url: the operation you want to perform, or cgi
Options:
Default attribute type description
Method Array 'post' HTTP request method.
Parameters String ''list of url format values passed in HTTP requests.
Asynchronous Boolean true specifies whether to perform asynchronous AJAX requests.
PostBody String undefined transmits the content in the Request body in the case of http post.
RequestHeaders Array undefined: the HTTP header list that is passed in with the request. This list must contain an even number of items. Any odd number of items is the name of the custom header, the following even number of items causes the string value of this header item. Example: ['my-header1', 'This is the value', 'My-other-header', 'Another value']
OnXXXXXXXX Function (XMLHttpRequest) undefined is the custom method called in an AJAX request when the corresponding event/status is formed. For example, var myOpts = {onComplete: showResponse, onLoaded: registerLoaded};. This method will be passed into a parameter, which is an XMLHttpRequest object carrying AJAX operations.
Onsuccess function (XMLHttpRequest) undefined the custom method called when the Ajax request is successfully completed. This method will be passed in a parameter, which is an XMLHTTPRequest object carrying Ajax operations.
Onfailure function (XMLHttpRequest) undefined the custom method called when the Ajax request is completed but an error occurs. This method will be passed in a parameter, which is an XMLHTTPRequest object carrying Ajax operations.
Insertion function (object, string) null is a method executed to inject the returned text into an element. This method will be passed in two parameters, the object to be updated and only applied to the response text of Ajax. Updater.
Evalscripts Boolean undefined and false determine whether to execute the script block when the response arrives, and apply it only in the Ajax. Updater object. That is, the JS Code of the target object must be set to true.
Decay number undefined, 1 determines that when the last response and the previous response are both in Ajax. the number of times that the periodicalupdater object reduces the number of man access. For example, if it is set to 2, the object will wait for the second set interval to refresh the same as the previous result, if it is the same again, it will wait four times. If you do not set this parameter, or set it to 1, the Access frequency will be reduced.
(Reference https://compdoc2cn.dev.java.net/prototype/html/prototype.js.cn.html#options_reference)

Simple Example:
I:
Index.html:

<Body> <script language = "javascript" src = "js/prototype. js "> </script> <script language =" javascript "> function doajax () {var ajax = new Ajax. updater ('My, "ajax. thtml ", {onComplete: function () {}, evalScripts: true });} </script> <div id = "my"> </div> <input type = "button" value = "click">

Ajax.html
<Body> <script language = "javascript"> test = function () {alert ("OK") ;}</script> <div style = "border: 1px silver solid; "> using ajax! <Input type = "button" value = "gettest"> </div> </body>

Note: To run the test () method in ajax.html, you must first set evalScripts: true, and then change the name of the test function to "function name = function. In addition, you can also run JSS in front of index.html without modifying the function.

II:
Forms can be submitted in a fresh way.
<Form action = "/action/here" method = "post">
The above code is displayed on wiki. script. aculo. us. If you are interested, go to the original article.


Firehack (Zhang zongrong) Super moderator

UID 3
Essence 15
Points 4651
Posts 1691
Read Permission 150
Register
StatusOnline

#2 Short Message published on February 14,


Font Size7pt8pt9pt10pt12pt15pt18pt20pt25pt30pt

Prototype is an open-source javascript development framework that encapsulates a large number of methods that can accelerate development. For example, you can use $ ('div ') instead of getElementById ("div "), it encapsulates xmlhttprequest and so on. The development frameworks of many languages, such as Ruby on Rails and symfony (PHP), are integrated with Prototype, and many more such as scripts. aculo. derivative works such as us, Rico, and Behaviour greatly expand the protopype function, which is convenient for Automatic completion, element dragging, flashing prompt, rounded rectangle prompt box, and text fading. This greatly improves the user experience. For designers, it greatly reduces the time spent on the UI. In the past, a long script code was required to achieve an effect, but now only one or two lines are required.
In Prototype, there are two main methods to implement asynchronous data transmission: Ajax. Updater and Ajax. Request.

[Copy to clipboard]

CODE:

Function getContents ()

{

Var request_url = "test1.html"; // url of the content to be retrieved

Var request_pars = ''; // Request Parameters

Var myAjax = new Ajax. Updater ('result', request_url, {// bind the content returned by request_url to the container whose id is result.

Method: 'get', // HTTP Request method, get or post

Parameters: request_pars, // Request parameters

OnFailure: reportError, // call the reportError function when a failure occurs.

OnLoading: loading, // when the content is being obtained

OnComplete: done // when the content is obtained

});

}

Function loading ()

{

$ ('Loading'). style. display = 'block ';

}

Function done ()

{

$ ('Loading'). style. display = 'none ';

}

Function reportError (request)

{

Alert ('sorry. There was an error .');

}

Ajax. updater provides three States for loading documents: onComplete, onLoading, and onFailure. we can customize a function to correspond to these three different states, so that we can make a Cool Loading prompt like Gmail.

 

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.