Javascript self-built Ajax wheel xcallback.2 only 6 KB

Source: Internet
Author: User

You may be bored with the configuration of the ajaxpro server and client, as well as Ms. net Ajax is huge, inefficient, and difficult to adapt to Clumsy styles, so many people are addicted to the JQ world, including me, so many Ajax frameworks have emerged, from the Internet, JQ seems to be the terminator of Ajax, but I feel that JQ is still inconvenient, so I plan to do it myself. I don't know if such an Ajax framework can impress you, let's take a look at a basic example. The following is a complete Ajax call process, which is more concise than JQ.

Function Test (v ){
Ajax. Reg ('X = '+ V );
Return;
Alert (Ajax. X );
}

Before return, it is the statement executed before the call, and after return, it is the statement to be executed after the server returns data, in which Ajax. X is the value returned by the server. this is a pure JS file that does not need to be configured on the server, and it has several obvious advantages over other Ajax frameworks:

1. built-in layer Display Effect During loading. You can customize the display position of the loaded layer at the full site level. Optional options include topleft, topright, center, bottomleft, bottomright). The default value is topright.

2. You can set whether to display the layer in some specific methods. For example, the following code does not show the effect of loading the layer when calling:

Function Test (v ){
Ajax. Visible = false;
Ajax. Reg ('X = '+ V );
Return;
Alert (Ajax. X );
}

3. A complete ajax exception handling program is built in. For example, if an exception is found on the server side, a div is displayed, showing the exception information, and jump to the special error page a few seconds later. By default, when an exception occurs, a div that displays 'exception occurred 'will pop up and jump to baidu.com 3 seconds later, you can skip to the page when an exception occurs during full-site configuration, as well as the interval, or even specify the effect and information of the pop-up div prompt.

4. Background support. If you need to judge the current Request type in page_load on the background, you just need to add this sentence to Request. Form ["isxcallback"]! = Null indicates that the request comes from the ajax of xcallback.2,

5. dynamic server-side control loading is more flexible than jq's load('demo.html '). The specific C # method is as follows:

To dynamically load a <asp: panel ID = "myPanel">

You only need to: GeneralHtml (myPanel)

Public String generalhtml (system. Web. UI. Control servercontrol)
{
System. Text. stringbuilder builder = new system. Text. stringbuilder ();
System. Io. stringwriter writer = new system. Io. stringwriter (builder );
System. Web. UI. htmltextwriter htmlwriter = new system. Web. UI. htmltextwriter (writer );
Servercontrol. rendercontrol (htmlwriter );
Return builder. tostring ();
}

Online Demo address: http://job.hrbust.edu.cn/fb/xcallback/

Demo: http://files.cnblogs.com/chenxumi/xcallback.rar

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.