调用网络服务 asmx 不工作
Call web service asmx not working
我正在创建 Web 服务 asmx,在通过“调用”按钮调用后工作正常。
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();
}
}
There is a mismatch in parameter name of your web method. Change 'idTest' to 'id'.
data: "{ id: '1', procedureName: 'sasatestUpdate' }"
我正在创建 Web 服务 asmx,在通过“调用”按钮调用后工作正常。
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();
}
}
There is a mismatch in parameter name of your web method. Change 'idTest' to 'id'.
data: "{ id: '1', procedureName: 'sasatestUpdate' }"