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