Reason for 'ajaxpro' undefined error & JavaScript sequential execution & ajaxpro Mechanism

Source: Internet
Author: User
The reason for the 'ajaxpro' undefined error & JavaScript sequence execution & ajaxpro mechanism reprinted:
Haha, I finally understood the cause of the 'ajaxpro' undefined error !!
Starting from JavaScript Execution MethodLet's start! I am familiar with C #. in C #, the location of any variable or function is irrelevant. For example, the following
Public void add ()
{
I ++;
}
Public void run ()
{
Add ();
}
Int I = 0;

There is no difference with the following method
Public void add ()
{
I ++;
}
Int I = 0;
Public void run ()
{
Add ();
}

But it won't work in Javascript. If you write it like this
Function add ()
{
I ++;
}
Add ();
VaR I = 0;

This will cause an error! Because the I in add is not defined (undefined )! Therefore, the JavaScript Execution method is sequential execution (not to mention whether C # Is sequential execution !)
Let's talk about it again.Ajaxpro Mechanism,
First, let's talk about what ajaxpro. Utility. registertypeforajax has done?
The basic principle of AJAX is actually very simple, that is, the XMLHttpRequest channel is asynchronous. Ajaxpro serves as the framework and package. We generally use ajaxpro in on_load. utility. registertypeforajax implements these functions (of course, here is ajaxpro. what exactly does ajaxmethod () work together? The server will not talk about it (I guess the cache method is used), in the client aspx (HTML) <form name = "form1" method = "Post" Action = "default3.aspx" id = "form1"> The following registration script is generated through viewstate.
<SCRIPT type = "text/JavaScript" src = "/web/ajaxpro/prototype. ashx"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "/web/ajaxpro/CORE. ashx"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "/web/ajaxpro/converter. ashx"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "/web/ajaxpro/default3, app_web_wvuzlcxq.ashx"> </SCRIPT>

The above Javascript is the Ajax framework and channel package implemented by ajaxpro.<SCRIPT type = "text/JavaScript" src = "/web/ajaxpro/CORE. ashx"> </SCRIPT>There areAjaxpro. onloadingStatement!
Which of the following is true?Cause of the 'ajaxpro' undefined ErrorNow!
This error occurs to me.
Default3.aspx
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default3.aspx. cs" inherits = "default3" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en ""Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns ="Http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
<SCRIPT type = "text/JavaScript">
Function get (r)
{
Document. getelementbyid ("M"). innertext = (R. value );
}
Ajaxpro. onloading = function (B ){
Document. getelementbyid ("loading"). style. Display = B? "Block": "NONE ";
}
</SCRIPT>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Div id = "loading" style = "display: none;"> obtaining server time
</Div>
<Div id = "M" style = "display: block;">
</Div>
<Input id = "but" type = "button" value = "button"/>

</Div>
</Form>
</Body>
</Html>
Default3.aspx. CS
...
Public partial class default3: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
Ajaxpro. Utility. registertypeforajax (typeof (default3 ));
}
[Ajaxpro. ajaxmethod]
// [Ajaxpro. ajaxservercache (10)]
Public String gett ()
{
System. Threading. thread. Sleep (2000 );
Return datetime. Now. tostring ();
}
}
You can see that I put ajaxpro. onloading to <Form ID = "form1" runat = "server">, that is, the source file
<SCRIPT type = "text/JavaScript" src = "/web/ajaxpro/prototype. ashx"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "/web/ajaxpro/CORE. ashx"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "/web/ajaxpro/converter. ashx"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "/web/ajaxpro/default3, app_web_wvuzlcxq.ashx"> </SCRIPT>
As Javascript is executed sequentially, The 'ajaxpro' undefined error occurs!
I changed the HTML file to the following:
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default3.aspx. cs" inherits = "default3" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en ""Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns ="Http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<SCRIPT type = "text/JavaScript">
Function get (r)
{
Document. getelementbyid ("M"). innertext = (R. value );
}
Ajaxpro. onloading = function (B ){
Document. getelementbyid ("loading"). style. Display = B? "Block": "NONE ";
}
</SCRIPT>
<Div>
<Div id = "loading" style = "display: none;"> obtaining server time
</Div>
<Div id = "M" style = "display: block;">
</Div>
<Input id = "but" type = "button" value = "button"/>

</Div>
</Form>
</Body>
</Html>
That's it!

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.