I'm trying to call server side method using ajax in asp C# application.
i have the following code in aspx file
function editApp(appID) {
$.ajax({
type: "POST",
url: "Default.aspx/GetSquare",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: "{}",
success: function (data) {
alert(data);
},
error: function () {
alert("Ajax Error");
}
});
}
and the following code in aspx.cs file
[WebMethod]
public static string GetSquare()
{
return "OK";
}
but in each time i call editApp function i get the following alert "Ajax Error"
Since you are not passing any parameters, mentioning as data: "{}"
is giving you errors. Instead you have to specify as data: {}
as shown below.
function editApp(appID) {
$.ajax({
type: "POST",
url: "Default.aspx/GetSquare",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: {},
success: function (data) {
alert(data);
},
error: function () {
alert("Ajax Error");
}
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.