Problems encountered by Ajax beginners: When JavaScript code is used to call the server code, the message 'webform1 'is not defined.

Source: Internet
Author: User

I caught up with a project over the past few days. I used Ajax and was ready to study it. But I encountered a strange problem when I first learned it,
I have searched the internet for a long time and no one has mentioned it. Are you doing well in this step? I use visualstudio2003, which is described as follows:
ASP. NET Ajax is mainly divided into five steps (a rough description ):

1 add Ajax reference
2 add in webconfig. xml
<Httphandlers>
<! -- Register the Ajax Handler -->
<Add verb = "post, get" Path = "ajax/*. ashx"
Type = "Ajax. pagehandlerfactory, Ajax"/>
</Httphandlers>
3. Add Ajax. Utility. registertypeforajax (typeof (webform1) to the page_onload () event ));
4. Mark the server code [Ajax. ajaxmethod ()]
5. Call the server in Javascript

The problem lies in the fifth step:
According to the Ajax quickguide, use webform1.getvalue () in JavaScript to call the server method (webform1 is the class I registered, and getvalue () is the server method I registered to call in Javascript ), the execution of IE prompts that "'webform1 'is not registered". It's a fucking thing. It's estimated that no one in the world will encounter this problem. After three days of reinstalling the system, I got nothing and was depressed.
Finally, we copied the JavaScript code in ASP. NET Condiments: Ajax, and solved the problem!

Copy JavaScript code segment (of course, some changes have been made in your program ):

<script language="javascript">WebForm1.GetValue(GetValue_CallBack);function GetValue_CallBack(response){alert(response.value);}</script>
Conclusion: The problem still lies in itself: the calling method in JavaScript code is asymmetrical with the method name defined by the server due to the rush to get the project,
Therefore, JavaScript does not recognize the variable webform1, prompting that 'webform1 'is not registered. In fact, you only need to check the code carefully.
I can find that, fortunately, I have a good determination, and I am dead with him. The problem is solved !!!

 

 

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.