How does Ajax call the data source on this page without a general handler?

Source: Internet
Author: User

Recently I have found some of my colleagues. When using Ajax and data sources, you all like to create a new page. in fact, I don't like this mode very much. The main reason is: first, it is difficult to maintain it in the future, what pages should I find, and second, I cannot call some original data methods on this page. so I did a test case here. As follows:

 

CSCode

 1   Using  System;  2   Using  System. Data;  3   Using  System. configuration;  4   Using  System. collections;  5  Using  System. Web;  6   Using  System. Web. Security;  7   Using  System. Web. UI;  8   Using  System. Web. UI. webcontrols;  9   Using  System. Web. UI. webcontrols. webparts;  10   Using System. Web. UI. htmlcontrols;  11   Using  System. Web. Services;  12   13   Public   Partial   Class  Testajax: system. Web. UI. Page  14   {  15       Protected   Void Page_load ( Object Sender, eventargs E)  16   {  17           String Methor = request [ "  Act  "  ];  18           If (! String  . Isnullorempty (methor ))  19   {  20              This . GetType (). getmethod (methor). Invoke ( This , Null  );  21   }  22   23   }  24   25       Public   Void  Getval ()  26   { 27           String Val = "  Getval  " + Request [ "  ARG  "  ];  28   Response. Clear ();  29   Response. Write (VAL );  30   Response. End ();  31  }  32   33 }

 

ASPX page

 1 <% @ Page Language = "  C #  " Autoeventwireup = "  True  " Codefile = "  Testajax. aspx. CS  " Inherits = " Testajax  " %> 2   3 <! Doctype HTML public "  -// W3C // dtd xhtml 1.0 transitional // en  "   "  Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd  " > 4   5 <HTML xmlns = "  Http://www.w3.org/1999/xhtml " > 6 <Head runat = "  Server  " > 7 <Title> No title page </title> 8 <SCRIPT type = "  Text/JavaScript  " Src = "  JS/jquery-1.8.1.min.js  " Language = " Javascript  " > </SCRIPT> 9 <Script language = "  Javascript  " Type = "  Text/JavaScript  " > 10      11   Function Test ()  12   {  13               14                    VaR Data = New  Object ();  15 Data. Act = "  Getval  "  ;  16 Data. Arg = "  123  "  ;  17 $. Post ("  Testajax. aspx  "  , Data, function (data) {alert (data );});  18   }  19 </SCRIPT> 20        21        22 </Head> 23 <Body> 24 <Form ID = "  Form1  " Runat ="  Server  " > 25 <Div> 26 <Input id = "  Button1  " Onclick = "  Test ()  " Type = "  Button  " Value = " Test Ajax  " /> 27   28 </Div> 29 </Form> 30 </Body> 31 </Html>

 

 

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.