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; }
2. The html code is as follows:
<form id="myform" runat="server"> <p> <asp:Button ID="bt" runat="server" Text="点击测试" /> </p> </form>
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; }); });
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!