0
jQueryとajaxを使用してWebメソッドに変数を渡そうとしています。私は変数を渡すための構文と混同され、成功していない多くの異なる形式を試しました。jQuery AJAXが変数をwebmethodに渡します。
WebMethod属性は次のとおりです。
public string GetStudentName(string studentID)
{
string name = string.Empty;
int id = 0;
// convert the string to an integer
id = int.Parse(studentID);
// If the studentID is withinrange
if (id < 0 || id >= _StudentList.Count)
{
name = "Not Found";
}
else
{
name = _StudentList[id].LastName + ", " + _StudentList[id].FirstName;
}
return name;
}
生徒のリストは、以前のコードで移入されます。
jQueryのコードは次のとおりです。
$('#cmdLookup').click(function()
{
var sid = $("#<%=txtID.ClientID%>").val();
$.ajax({
type: "POST",
url: "Services/WSStudent.asmx/GetStudentName",
contentType: "application/json; charset=utf-8",
data: sid,
dataType: "json",
success: function (result)
{
$('#<%=txtStudentName.ClientID%>').text(result.d);
},
error: function (XMLHttpRequest, textStatus, errorThrown)
{
alert('Error: ' + XMLHttpRequest.responseText);
}
})
})
誰かが私に素晴らしいことだSID変数を渡すための正しい構文を示すことができた場合。
をしたいSID変数が値を持っていることを確認してくださいどのようにこのASPは、古典的なのですか? ASP.NETのように見えます。 – mikeyq6