Я работаю над приложением веб-форм asp.net. Я пытаюсь сделать вызов ajax для веб-метода в codebehind, но вместо того, чтобы возвращать результат, он возвращает целую html-страницу.Ajax вызов, возвращающий всю страницу html в asp.net веб-формы
Я зову его на кнопку мыши
<input type="button" id="btnCallAPIFromClient" class="btn btn-success" value="Call API from Client"/>
Мой JS скрипт:
$(document).ready(function() {
//PageMethods.set_path(PageMethods.get_path() + '.aspx');
$('#btnCallAPIFromClient').click(function() {
alert('here');
$.ajax({
url: '/login/GetAccessToken',
type: "POST",
dataType: 'html',
success: function(response) {
alert(response);
debugger;
sessionStorage.setItem("accessToken", response.access_token);
alert(response.access_token);
},
// Display errors if any in the Bootstrap alert <div>
error: function(jqXHR) {
alert(jqXHR.responseText);
}
});
});
});
WebMethod является:
[WebMethod]
public static string GetAccessToken()
{
return "abc";
}
С уважением, Азиф Хамид
Уведомление 'dataType: 'html',' try once with 'dataType:" text ",' – Satpal
Также добавьте 'contentType:" application/json; charset = utf-8 ", dataType:" json "' –