How does jquery call the background method?

Source: Internet
Author: User
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

  1. <% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %>
  2. <! Doctype HTML public "-// W3C // dtd xhtml 1.1 // en" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  3. <HTML xmlns = "http://www.w3.org/1999/xhtml">
  4. <Head runat = "server">
  5. <Title> untitled page </title>
  6. <SCRIPT type = "text/JavaScript" src = "jquery. js"> </SCRIPT>
  7. <Script language = "JavaScript">
  8. $ (Document). Ready (function (){
  9. $ ("# Result"). Click (function (){
  10. $. Ajax ({
  11. Type: "Post ",
  12. URL: "default. aspx/getdate", // pay attention to the call method. You can call WebService in the same way.
  13. Data: {}, // here you can set the parameters to be passed
  14. Contenttype: "application/JSON; charset = UTF-8 ",
  15. // Datatype: "JSON ",
  16. Success: function (MSG) {// Replace the returned content
  17. $ ("# Result"). Text (MSG );
  18. },
  19. Error: function (xhr, MSG, e ){
  20. Alert (MSG );
  21. }
  22. });
  23. });
  24. });
  25. </SCRIPT>
  26. </Head>
  27. <Body>
  28. <Form ID = "form1" runat = "server">
  29. <Div id = "result"> click here. </div>
  30. </Form>
  31. </Body>
  32. </Html>

Background defaule. aspx. CS

Copy code

  1. Using system;
  2. Using system. Data;
  3. Using system. configuration;
  4. Using system. Web;
  5. Using system. Web. Security;
  6. Using system. Web. UI;
  7. Using system. Web. UI. webcontrols;
  8. Using system. Web. UI. webcontrols. webparts;
  9. Using system. Web. UI. htmlcontrols;
  10. [System. Web. Script. Services. scriptservice]
  11. Public partial class _ default: system. Web. UI. Page
  12. {
  13. Protected void page_load (Object sender, eventargs e ){}
  14. [System. Web. Services. webmethod]
  15. Public static string getdate () {return datetime. Now. tostring ();}
  16. }

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.