没有从jquery调用webservice / web方法 [英] webservice/web method not getting called from jquery
问题描述
这个webmethod / webservice调用中的问题
whats the problem in this webmethod/webservice call
$.ajax({
type: "GET",
url: "jquerygrid.aspx/GetCustomers",
dataType: "json",
success: function(resp){
// we have the response
alert("Server said123:\n '" + resp+ "'");
},
error: function(e){
alert('Error121212: ' + e);
}
});
GetCustomers是我在jquerygrid.aspx页面中的方法的名称。
i也尝试调用webservice方法喜欢autocomplete.asmx / getcustomers。
以下是我的webmethod
GetCustomers is name of my method in jquerygrid.aspx page.
i also tried to call a webservice method like autocomplete.asmx/getcustomers.
Following is my webmethod
[System.Web.Services.WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public static string GetCustomers()
{
string query = "SELECT * FROM table";
SqlCommand cmd = new SqlCommand(query);
// Populate the DataSet.
DataSet data = GetData(cmd);
string strjson = GetJson(data.Tables[0]);
return strjson;
}
推荐答案
.ajax({
type: GET,
url: jquerygrid.aspx / GetCustomers,
dataType: json ,
成功: function (resp){
// 我们有响应
alert( Server said123:\ n' + resp + ');
},
错误: function (e){
alert(' Error121212:' + e);
}
});
.ajax({ type: "GET", url: "jquerygrid.aspx/GetCustomers", dataType: "json", success: function(resp){ // we have the response alert("Server said123:\n '" + resp+ "'"); }, error: function(e){ alert('Error121212: ' + e); } });
GetCustomers是我在jquerygrid.aspx页面中的方法的名称。
i也尝试调用webservice方法喜欢autocomplete.asmx / getcustomers。
以下是我的webmethod
GetCustomers is name of my method in jquerygrid.aspx page.
i also tried to call a webservice method like autocomplete.asmx/getcustomers.
Following is my webmethod
[System.Web.Services.WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public static string GetCustomers()
{
string query = "SELECT * FROM table";
SqlCommand cmd = new SqlCommand(query);
// Populate the DataSet.
DataSet data = GetData(cmd);
string strjson = GetJson(data.Tables[0]);
return strjson;
}
您必须将此行添加到您的ajax调用
You have to add this line to you ajax call
contentType: 'application/json; charset=utf-8',
(在dataType之后......)
(Just after dataType...)
添加数据属性并更改在jquery ajax调用中键入to post
Add data attribute and change type to Post in the jquery ajax call
这篇关于没有从jquery调用webservice / web方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!