It took a long timeArticleToday, I finally started writing. The time is too short and the writing is messy. I will sort it out when I have time. Here I will first post a preview version to explain it to myself. This article mainly analyzes the three JS files of the ajaxpro client Class Library:
Prototype. ashx
As you know, JavaScript is a prototype-driven language. To expand the Javascript language, you must start with prototype and expand the JavaScript Functions and object objects.
This article focuses on analyzing prototype applications in ajaxpro, but you must briefly introduce prototype:
With prototpe, we can add some "instance methods" for the object (for example, the same below). Please refer to the followingCodeNote the difference between the definition and use of the test and Test2 methods.
< Script >
String. Prototype. Test = Function (S ){ Return S ;}; // Define an instance method
String. Test2 = Function (S ){ Return S ;}; // Define static methods
VaR Str1 = " Truly " ;
Alert ( Typeof Str1.test + " \ N " + // Function, instance reference
Typeof Str1.test2 + " \ N " + // Undefined, instance reference
Typeof String. Test + " \ N " + // Undefined, static reference
Typeof String. Test2 ); // Function, static reference
Alert (str1.test ( " Instance call " )); // Call the instance method correctly
Alert (string. Test2 ( " Static call " )); // Call the static method correctly
</ Script >
Prototype is beyond the scope of this article. If you are interested, search by Google.
Next, we will analyze the prototype of the first file. ashx. You can use http: // localhost/ajaxpro/prototype in IE. open ashx and save it, or prototype in ajaxpro source code. open the JS file with a text editor or a development tool such as vs. You can see that this file first defines an extend method for the object, which is the underlying public method of the ajaxpro client class library, it is used to add or replace attributes and methods of any object (functions and objects.
The Code is as follows:
Object. Extend = Function (DEST, source, replace ){
For (VAR prop In Source ){
If (Replace = False && Dest [prop] ! = Null ){ Continue ;}
Dest [prop] = Source [prop];
}
Return DeST;
};
Continue to read the source code and find that the following Code expands the examples and static methods of function, array, string and other JavaScript objects by using the extend method.
First, the bind method is added for the function in the prototype mode, and the built-in apply method in Javascript is overwritten. This includes prototype. all functions on the ashx page have the bind method and the new apply method.
Note:ApplyOriginally a built-in method of JavaScript, it is used to apply a method of an object and replace the current object with another object.
Core. ashx
Core. ashx, as its name implies, is the core of ajaxpro. It mainly defines the ajaxpro client type and provides some operation methods.
Like prototype. ashx, open it using an editor or development tool. In the core. ashx source code, the getarguments instance method is added to the function in prototype mode.
To better understand this important method, first we need to understand the arguments object in javascript:
Arguments: It is a function attribute and returns an arguments object for the currently executed function object. The arguments attribute allows the function to process variable numbers of parameters. The Length attribute of the arguments object contains the number of parameters passed to the function. For a single parameter contained in an arguments object, the access method is the same as the access method of the parameter contained in the array.
The getarguments method defined here is used to convert the arguments attribute of the currently executed function object into an array to return.
In core. after the getarguments method is extended in ashx, it defines another Ms object, including a child object browser, which has three static attributes to indicate the browser of the current client. For example, we can use the following code to determine whether the client is an IE browser.
< Script >
If (Ms. browser. isie)
Alert ('You use a IE browser .');
</ Script >
NextAjaxproThe definition of objects. Many Sub-objects, methods, and attributes are also defined under the ajaxpro object. See the table below.
| Name |
Type |
Description |
| Iframexmlhttp |
|
|
| Nooperation |
|
|
| Onloading |
|
|
| Onerror |
|
|
| Ontimeout |
|
|
| Onstatechanged |
|
|
| Queue |
|
|
| Tojson |
|
|
| Dispose |
|
|
| Request |
|
|
| Requestqueue |
|
|
| Ajaxclass |
|
Contains the invoke instance method and URL static attributes |
| Cryptprovider |
|
|
| Token |
|
|
| Version |
|
|
| ID |
|
|
| Noactivex |
|
|
| Timeoutperiod |
|
|
The final core function here is iframexmlhttp, which is the final interaction between the entire Asynchronous Operation and the server.
Coverter. ashx
Converter. ashx maps some. Net types to client types. There are five types of conversions, which are
- Namevaluecollectionconverter
- Datasetconverter
- Datatableconverter
- Profilebaseconverter
- Idictionaryconverter
/*
// Namevaluecollectionconverter
Map system. Collections. Specialized. namevaluecollection In the. NET class library to Ajax. Web. namevaluecollection.
Defines a client's key-value collection class (Ajax. Web. namevaluecollection), with ADD, containskey, getkeys, getvalue, setvalue, tojson instance method Member
Field attributes include _ type, keys, and values. Return the type string, key set, and value set respectively.
// Datasetconverter
System. Data. dataset, system. Data
Defines the dataset collection class (Ajax. Web. dataset) of a client and has a member of The addtable instance method.
Field attributes include _ type and tables. Return the type string and table set respectively.
// Datatableconverter
System. Data. datatable, system. Data
Defines a client's able collection class (Ajax. Web. datatable), with AddColumn, tojson, addrow instance method Member
Field attributes include _ type, columns, and rows. Return the type string, column set, and row set respectively.
// Profilebaseconverter
Defines the Ajax. Web. Profile class
The members are as follows:
Field:
Method: setproperty_callback, setproperty
// Idictionaryconverter
Ajax. Web. dictionary class
The members are as follows:
Field __type, keys, values. Return the type string, key set, and value set respectively.
Method: add, containskey, getkeys, getvalue, setvalue, tojson
*/
----------------------------------------------------
Onloading demo
<SCRIPT type = "text/JavaScript" Defer = "Defer">
VaR C = 0;
Ajaxpro. onloading = function (B ){
C ++;
Window. Status = C;
VaR L = Document. getelementbyid ("loadinfo ");
L. style. Visibility = B? "Visible": "hidden ";
}
Function dotest1 (){
C = 0;
ASP. loadingdemo. longoperation (dotest?callback );
}
Function dotest1_callback (RES ){
Alert (res. value );
}
</SCRIPT>
(To be updated)