我需要调用我在Web服务中传递的参数来获取sql server中的存储过程值,但是我知道这很快就打电话了
<script type="text/javascript">
function ExecuteAJAXCall() {
$.ajax({
type: "POST",
url: "Name.asmx/GetUserDetails",
data: "{'name':'" + $("#txtename").val() + "'}",
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: Callback_AJAXCall
});
};
function Callback_AJAXCall(data) {
document.getElementById("DataContainer").innerHTML = "the result is: " + data.d;
};
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>
AJAX call test page</h2>
<input type="text" id="txtname" />
<button type="button" onclick="ExecuteAJAXCall()";>
Getdetails</button>
<br />
<br />
<div id="DataContainer">
</div>
</div>
</form>
</body>
</html>
请检查我的代码以传递参数,如果我调用它显示reult为null
答案 0 :(得分:0)
请尝试这个
function ExecuteAJAXCall() {
$.ajax({
type: "POST",
url: "Name.asmx/GetUserDetails",
data: {name:$("#txtename").val()},
contentType: "application/json; charset=utf-8",
dataType: 'json',
success: Callback_AJAXCall
});
};
答案 1 :(得分:0)
试试这个:因为您的数据类型是json,然后使用data[d]
来调用您的结果数据。
function Callback_AJAXCall(data) {
document.getElementById("DataContainer").innerHTML = "the result is: "+data[d];
};
答案 2 :(得分:0)
public string GetUserDetails(string name)
{
con.Open();
SqlCommand cmd = new SqlCommand("exec sp_n @name='" + name + "'", con);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText = "sp_n";
cmd.Parameters.AddWithValue("@name", name);
cmd.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
//XmlDataDocument xmldata = new XmlDataDocument(ds);
//XmlElement xxx = xmldata.DocumentElement;
return ds.GetXml();
}
最初我没有返回ds.GetXml