The preferred Ajax framework for prototype. js lightweight web development (III)

Source: Internet
Author: User

This article mainly describes how to use Ajax in prototype. js for some small application development, without the Ajax principle.

In prototype. JS, I will use two Ajax classes later. One isAjax. RequestAnother isAjax. Updater. Ajaxrequest inherited fromAjax. base.WhileAjax. UpdaterInherited fromAjax. Request, Which has no other meaning, mainly to make readers understand that with the continuation of inheritance, the functions of the class will also be specialized.

I am a rough man, but I have to say so many things. Let's start with an example. Oh, I almost forgot to mention one thing. Ajax cannot use cross-origin requests by default in common browsers such as XP, but cannot join Trusted Sites in 2003. Therefore, some applications cannot be implemented using Ajax. Otherwise, remember to leave a path for yourself, like Gmail, which uses Ajax by default, however, if the system cannot execute Ajax, the system prompts that users can implement it using common HTML. Cross-origin is also called. For example, if my domain name is www.lvjiyong.com, I can use ajax to request all resources that can be accessed by www.lvjiyong.com. If I want to access resources under www.1818city.com, the browser will reject the request, some people want to use ajax to upload files. The feasibility is even more exaggerated. The security level must be minimized. In addition, you are allowed to access resources in any domain during local testing. Do not attempt to directly use Ajax on the website to obtain information from other websites, in ASP, we can use the XMLHTTP Implementation of the server, while in.. net.

Well, let's give an example. Let's talk about the specialAjax. Updater.I wonder if the reader has attempted to register a member of this blog. The verification code is used.Ajax. UpdaterTo achieve this, register an event when loading the page to monitor the changes in the verification code input box. When the entered long character conforms to the Verification code length, it will automatically triggerAjax. UpdaterThe verification code page sends a request. If the system detects a verification code error, the system returns "Verification code error". Otherwise, a null value is returned, indicating that the verification code is correct. WhileAjax. UpdaterIn this case (only the returned values need to be displayed ).

<SCRIPT>
Function gethtml ()
{
VaR url = 'HTTP: // www.lvjiyong.com/1818city/default.aspx ';
VaR pars = 'test = lvjiyong.com ';

VaR myajax = new Ajax. Updater (
'Placeholder ',
URL,
{
Method: 'get ',
Parameters: pars
});

/*

The get method is mainly used to pass a few parameters. Remember that it is only suitable for transferring a small number of parameters. In 'HTTP: // www.lvjiyong.com/18city/default.aspx', there is no progress on the parameters. Only what transmission parameters are displayed.

The passing parameters are divided into post and get parameters, which should be known to all users. When post is used, request is used. form ["parameter name"] value. request is used for get. querystring ["parameter value"] value. After data is processed back, the response text is automatically filled into the container with the ID of placeholder.

The format of post submission is as follows: (the main note is to pass the post data. Of course, you can also write a parameter in the URL to pass the querystring value .)

VaR postdata = "content ";

VaR myajax = new Ajax. Updater (
'Placeholder ',
URL,
{
Method: 'post ',
Postbody: postdata });

*/

}
</SCRIPT>

<Input type = button value = gethtml onclick = "gethtml ()">
<Div id = "Placeholder"> </div>

By default, you can use this method for requests, but you can set more parameters in detail, which will be used later.Ajax. RequestFor more information.

I started to think about it. Stop it first. Recently, my mental state has been poor. let's talk about the parameters tomorrow and explain how to implement the "loading... ", and automatically disappears after successful.

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.