Share the AjaxPro or Ajax implementation mechanism

  • 2020-05-16 06:42:14
  • OfStack

Let me begin by stating the following:
If you feel very elementary, even if I installed 13, do not "spray" me!
2, if there are those places wrong, I hope you can correct, 1 will be modest to consult;
3, this is just a word, my experience, no basis, love believe it or not.
Let's move on:
Those who have done ajax's web development are familiar with xmlhttp request, which is to communicate with the server side through xmlhttp request and avoid pressing f5 on the page. That is, we often say "no refresh", as for the principle of here I do not understand, which understand, teach 1 I ah, thank you!
To use ajaxpro, we generally do the following:
1. Add a reference ajaxpro.2.dll, go to the next 1 on the Internet, if not, I will share 1 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 where you want to use the ajax function, for example:
protected void page_load(object sender,eventargs e)
{// register ajax ajaxpro.utility.registertypeforajax (typeof(default)); }
4. Declare methods (or properties) that can be called by ajax in the.cs file, such as:
[ajaxpro ajaxmethod]
public string getstr () {return "str"; }
5, in the.aspx file < head > < /head > Between adding js and calling ajax, as follows:
 
  <script language="javascript"> 
  var item=dynloadtree.default.getstr().value;//ajax Calling the background method  
  alert(item); 
  </script> 

By doing the above 5 steps, we have basically achieved the function of not pressing f5 on the ajax page. How does it communicate with the server via xmlhttp? After running, we can see that the source code of html file is a few more lines.
 
  <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 automatically add these caches to the html document output when registering ajax in step 3 above, ajaxpro.utility.registertypeforajax. What are these files? Look again at the configuration added to httphandlers in web.config in step 2. It tells the system that all requests received in the ajaxpro path that have the ashx suffix are passed to the ajaxpro.ajaxhandlerfactory class for processing, and these ashx files are returned as javascript files after processing, which is no different from the normal js cache.
Good, and I said so much, if you are interested can go to study the above every 1. ashx files inside function, alas, is I don't have time to make, the Internet also has a lot of information about this aspect, and cattle X ajaxpro directly. 2. dll decompiling, you can also go to see the inside of the code, may be more fruitful, hehe...
PS: Tandy Tang have fun writing code!

Related articles: