J'ai essayé d'appeler Simple Web Method à partir de JSON, mais j'obtiens des erreurs.SyntaxError: JSON.parse
En Chrome:
SyntaxError: unexpected token <
Dans Firefox:
SyntaxError: JSON.parse
code 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
Code:
<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;
}
S'il vous plaît me guide ...
Votre code côté serveur ne sera même pas compilé. Vous ne pouvez pas renvoyer une valeur d'une méthode déclarée comme «void». Donc, la première étape serait de réparer et de compiler votre code côté serveur. Ensuite, nous verrons à propos du client. –