Я пытался вызвать простой веб-метод из JSON, но получаю ошибки.
в Chrome:
SyntaxError: неожиданный токен <</p>
В Firefox:
SyntaxError: JSON.parse
Javascript код:
$(document).ready(function() {
$('#<%=ddlTest.ClientID %>').change(function() {
var value = $('#<%=ddlTest.ClientID %>').val();
var req = $.ajax({
type: "POST",
url: "Test.aspx/getTest",
data: "{Id: '" + value + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
$(alert(data.d))
},
error: function(XMLHttpRequest, text, error) { alert(error); },
failure: function(response) {
alert(response.d);
}
})
});
});
.aspx
код:
<asp:DropDownList ID="ddlTest" AutoPostBack="false" runat="server">
<asp:ListItem Value="0" Text="zero" />
<asp:ListItem Value="1" Text="One" />
<asp:ListItem Value="2" Text="Two" />
</asp:DropDownList>
<asp:Label ID="lblTest" runat="server" Text="hiii"/>
WebMethod:
[WebMethod]
public static string getTest(string id)
{
return id;
}
Пожалуйста, ведите меня ...