Share the AjaxPro or Ajax Implementation Mechanism

Source: Internet
Author: User

First, declare the following:
1. If I feel very elementary, I will install 13. Don't "spray" me!
2. If there are any mistakes, I hope you can correct them and consult them modestly;
3. This is just a saying of the family. I have experience and have no evidence. Believe it or not.
Let's start with the following:
I am very familiar with ajax web development, that is, through the process of xmlhttp request to communicate with the server to avoid page press f5. That is what we often call "no refreshing". I don't understand the principles here. If you know anything, please teach me. Thank you!
To use ajaxpro, we should do the following:
1. Add the reference ajaxpro.2.dll to the project. Click here. If not, share it if I have time;
2. Add in the web. config configuration file <
Add verb = "post, get" path = "ajaxpro/*. ashx" type = "ajaxpro. ajaxhandlerfactory, ajaxpro.2"/> node;
3. Register ajax on the page. cs file to use ajax functions, for example:
Protected void page_load (object sender, eventargs e)
{// Register ajax ajaxpro. utility. registertypeforajax (typeof (default ));}
4. Declare the methods (or attributes) that can be called by ajax in the. cs file, for example:
[Ajaxpro. ajaxmethod]
Public string getstr () {return "str ";}
5. Add js to call ajax between Copy codeThe Code is as follows: <script language = "javascript">
Var item = dynloadtree. default. getstr (). value; // ajax calls the background Method
Alert (item );
</Script>

After completing the above five steps, we basically implemented the function of not pressing f5 on the ajax page. So how does it communicate with the server through xmlhttp? After running the command, we can see that the source code of the html file has several more lines of. ashx File Cache:Copy codeThe Code is as follows: <script type = "text/javascript" src = "/ajaxpro/prototype. ashx" </script>
<Script type = "text/javascript" src = "/ajaxpro/core. ashx" </script>
<Script type = "text/javascript" src = "/ajaxpro/converter. ashx" </script>
<Script> type = "text/javascript" src = "/ajaxpro/dynloadtree. default, dynloadtree. ashx" </script>

In fact, these. ashx will automatically add these caches to the html document output when registering ajax in step 3rd ajaxpro. utility. registertypeforajax. What are these files? Let's look at the web in step 1. the configuration added to the httphandlers section in config tells the system to send all requests that have been suffixed with ashx in the ajaxpro path to ajaxpro. the class ajaxhandlerfactory is used for processing, and some javascript files are returned after these ashx are processed, which is no substantive difference from common js cache.
Well, I will say so much. If you are interested, you can study each of the above. the functions in the ashx file, alas, I don't have time to get them done. There are also a lot of information about this on the internet, and Niu X people directly decompile ajaxpro.2.dll, you can also look at the code in it, which may be more rewarding ......
PS: Tandy Tang I wish you a pleasant time writing your code!

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.