[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public static string getJsonString()
{
Person p = new Person();
p.name = "Alex";
p.address = "UK";
string jsonString;
jsonString = JsonConvert.SerializeObject(p);
return jsonString;
}
}
$("#clickme").on('click', function () {
$.ajax({
type:"GET",
url: "JsonPage.aspx/getJsonString",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (response) {
debugger;
$("#name").text(response.d.name);
$("#address").text(response.d.address);
},
error: function (jqXHR, exception) {
var msg = '';
if (jqXHR.status === 0) {
msg = 'Not connect.\n Verify Network.';
} else if (jqXHR.status == 404) {
msg = 'Requested page not found. [404]';
} else if (jqXHR.status == 500) {
msg = 'Internal Server Error [500].';
} else if (exception === 'parsererror') {
msg = 'Requested JSON parse failed.';
} else if (exception === 'timeout') {
msg = 'Time out error.';
} else if (exception === 'abort') {
msg = 'Ajax request aborted.';
} else {
msg = 'Uncaught Error.\n' + jqXHR.responseText;
}
alert(msg);
}
})
})
});
Я пытаюсь вызвать webmethod, используя jquery ajax-тип: "GET", первая проблема в том, что точка останова в методе не задана. и во-вторых, в браузере я получаю сообщение об ошибке "Запрошенный анализ JSON не выполнен". Что делать, пожалуйста, помогите ...