A method based on how JavaScript implements AJAX invoke background definitions _jquery

Source: Internet
Author: User

Because of the unique advantages of Ajax, so that it in the current large number of Web sites have been widely used, the following describes how Ajax calls the background-defined functions, although relatively simple, but hope to bring some help for beginners, the code is as follows:

1. First we create a antzone.aspx page.

2. Create the following function in its CS file:

public static string MyTest (string A, string second) 
{return return 
  First+second; 

The 2.html code is as follows:

<form id= "MyForm" runat= "Server" > 
<div> 
 <asp:button id= "BT" runat= "Server" text= "click Test"/> 
</div> 

The 3.javascript code is as follows:

$ (function () { 
 $ ("#bt"). Click (function () { 
  $.ajax ({ 
   type: Post), 
   URL: "Antzone.aspx/mytest", 
   Data: "{' I ': ' Ant Tribe ', ' second ': ' Welcome you '}", 
   contentType: "Application/json;charset=utf-8", 
   dataType: "JSON", 
   success:function (data) { 
    //returned DATA.D get content 
    alert (DATA.D); 
   }, 
   error:function (err) { 
    alert (err); 
   } 
  ); 
  Disable submit return False for button; 
  

The code above implements the functionality we need to invoke the function defined in the background. How to realize the definition of Ajax call background based on jquery first to introduce to you here, where there is no understanding of the place to welcome your message, thank you.

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.