Application of IFRAME in Ajax

Source: Internet
Author: User

Asp.net MVC supports Ajax well, but for those who use vs2005 to develop Ajax as elegantly as Asp.net MVCProgramThere are too many things to implement by yourself. I used IFRAME to implement Ajax effects without making major changes to the projects passed in.

 

Core AjaxCodeAs follows:

 

Code
1 VaR Frameajaxdic =   New Object ();
2 VaR Frameajax =   Function (ID, onstart, oncomplete) {
3 This . _ Id = ID
4 If (Frameajaxdic [ This . _ Id] ! =   True ) {
5 $ ( " Body " ). Append ( " <IFRAME Style = 'display: none' src = 'about: blank 'id =' "   +   This . _ Id +   " 'Name =' "   +   This . _ Id +   " '> </Iframe> " );
6 Frameajaxdic [ This . _ Id] =   True ;
7 }
8 This . Onstart = Onstart;
9 This . Oncomplete = Oncomplete;
10 This . Isformpost =   False ;
11 }
12 Frameajax. Prototype =   {
13 GETID: Function () {
14Return This. _ Id;
15} ,
16 Submit: Function (Form) {
17 If ( ! This . Isformpost) {
18 $ (Form). ATTR ( " Target " , This . _ Id );
19 VaR Self =   This ;
20 If ( This . Onstart ! =   Null ) {
21 This . Isformpost =   This . Onstart ();
22 If ( This . Isformpost) {
23 $ ( " # "   +   This . _ Id). Load ( Function () {Self. _ onframeload ();} );
24 }
25 }
26 }
27 Return   This . Isformpost;
28 } ,
29 _ Onframeload: Function () {
30 If ( This . Isformpost) {
31 This . Isformpost =   False ;
32 If ( This . Oncomplete ! =   Null ) {
33This. Oncomplete ($ ("#" + This. _ Id). Contents (). Text ());
34}
35 $ ( " # "   +   This . _ Id). Unbind ( " Load " );
36 }
37 } ,
38 Despose: Function () {
39 This . Onstart =   Null ;
40 This . Oncomplete =   Null ;
41 $ ( " # "   +   This . _ Id). Remove ();
42 Frameajaxdic [ This . _ Id] =   Null ;
43 }
44 }

 

The intention of this JavaScript Object is to create an IFRAME, which transfers the operations submitted to this page to the IFRAME for submission, so that the commit page is not refreshed, and the server side returns the execution result to IFRAME.

The following are three applications of this Code: 1. Upload 2. Add a single object 3. Add multiple objects.

Iframeajax application example

 

 

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.