The younger brother wants to use jquery to call the background method, but the HTML code of the entire page is returned now. What are the reasons for the experts and how should they modify it?
The Code is as follows:
Foreground defalut. aspx
Copy code
- <% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %>
- <! Doctype HTML public "-// W3C // dtd xhtml 1.1 // en" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
- <HTML xmlns = "http://www.w3.org/1999/xhtml">
- <Head runat = "server">
- <Title> untitled page </title>
- <SCRIPT type = "text/JavaScript" src = "jquery. js"> </SCRIPT>
- <Script language = "JavaScript">
- $ (Document). Ready (function (){
- $ ("# Result"). Click (function (){
- $. Ajax ({
- Type: "Post ",
- URL: "default. aspx/getdate", // pay attention to the call method. You can call WebService in the same way.
- Data: {}, // here you can set the parameters to be passed
- Contenttype: "application/JSON; charset = UTF-8 ",
- // Datatype: "JSON ",
- Success: function (MSG) {// Replace the returned content
- $ ("# Result"). Text (MSG );
- },
- Error: function (xhr, MSG, e ){
- Alert (MSG );
- }
- });
- });
- });
- </SCRIPT>
- </Head>
- <Body>
- <Form ID = "form1" runat = "server">
- <Div id = "result"> click here. </div>
- </Form>
- </Body>
- </Html>
|
Background defaule. aspx. CS
Copy code
- Using system;
- Using system. Data;
- Using system. configuration;
- Using system. Web;
- Using system. Web. Security;
- Using system. Web. UI;
- Using system. Web. UI. webcontrols;
- Using system. Web. UI. webcontrols. webparts;
- Using system. Web. UI. htmlcontrols;
- [System. Web. Script. Services. scriptservice]
- Public partial class _ default: system. Web. UI. Page
- {
- Protected void page_load (Object sender, eventargs e ){}
- [System. Web. Services. webmethod]
- Public static string getdate () {return datetime. Now. tostring ();}
- }
|