我正在创建web服务asmx,通过Invoke按钮调用后工作正常。
Parameter: id = 1 procedureName = sasatestUpdate
现在我通过Ajax调用服务但没有任何反应。
示例:
function callService() {
$.ajax({
type: "POST",
url: "appws.asmx?myServiceUpdate",
data: "{ idTest: '1', procedureName: 'sasatestUpdate' }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) { alert("success") },
failure: function (errMsg) { alert("failure"); }
});
}
我没有得到任何警报(成功或失败)......
网络服务
string constring = "Data Source=myDb";
SqlConnection conn;
SqlCommand comm;
[WebMethod]
public string myServiceUpdate(string id, string procedureName)
{
conn = new SqlConnection(constring);
conn.Open();
comm = new SqlCommand();
comm.Connection = conn;
comm.CommandType = System.Data.CommandType.StoredProcedure;
comm.CommandText = procedureName;
comm.Parameters.AddWithValue("@idTest", id);
try
{
comm.ExecuteNonQuery();
return "Record Saved";
}
catch (Exception)
{
return "Not Saved";
}
finally
{
conn.Close();
}
}
答案 0 :(得分:1)
There is a mismatch in parameter name of your web method. Change 'idTest' to 'id'.
数据:“{id:'1',procedureName:'sasatestUpdate'}”