Home > Web Front-end > JS Tutorial > body text

JS implements ajax call background definition (with code)

php中世界最好的语言
Release: 2018-04-25 15:51:40
Original
1768 people have browsed it

This time I will bring you JS to implement ajax call background definition (with code). What are the precautions for JS to implement ajax call background definition. The following is a practical case, let's take a look.

1. First we create an antzone.aspx page.

2. Create the following function in its cs file:

public static string mytest(string first, string second) 
{ 
  return return first+second; 
}
Copy after login

2. The html code is as follows:

<form id="myform" runat="server"> 
<p> 
 <asp:Button ID="bt" runat="server" Text="点击测试" /> 
</p> 
</form>
Copy after login

3.javascriptThe code is as follows:

$(function(){ 
 $("#bt").click(function(){ 
  $.ajax({ 
   type:"Post", 
   url:"antzone.aspx/mytest", 
   data:"{'first':'PHP','second':'欢迎您'}", 
   contentType:"application/json;charset=utf-8", 
   dataType:"json", 
   success:function(data){ 
    //返回的数据用data.d获取内容 
    alert(data.d); 
   }, 
   error:function(err){ 
    alert(err); 
   } 
  }); 
  //禁用按钮的提交 
  return false; 
 }); 
});
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Detailed explanation of the use of AJAX request queue

Detailed explanation of JSONP implementation principles and cases

The above is the detailed content of JS implements ajax call background definition (with code). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template