Я написал одну общую функцию AJAX.Вместо того, чтобы писать несколько раз.Так что я просто отправляю данные поста и URL на мою обычную функцию.До сих пор все в порядке, и я тоже получаю ответ.Но я испытываю затруднения при чтении этого ответа.
function _ajax_post(someData,URL)
{
var ajaxCall = $.ajax({
type: 'POST',
data: someData,
dataType: 'json',
url: URL
});
ajaxCall.done(function(data) {
console.log("A good programmer looks both ways before crossing a one-way street :) ");
});
ajaxCall.fail(function(data) {
console.log(" Design is choosing how you will fail.");
});
ajaxCall.always(function() {
console.log("Truth can only be found in one place: the code.");
});
return ajaxCall;
}
Здесь я звоню как
$('#btnOutput').on('click', function () {
var str = $("#out").text();
var r = _ajax_post({"data":str},url+"roles/vu_menus/tets");
console.log(r);
});
В моем console.log () я получаю ответ как
{readyState: 1, getResponseHeader: ƒ, getAllResponseHeaders: ƒ, setRequestHeader: ƒ, overrideMimeType: ƒ, …}
abort: ƒ (a)
always: ƒ ()
complete: ƒ ()
done: ƒ ()
error: ƒ ()
fail: ƒ ()
getAllResponseHeaders: ƒ ()
getResponseHeader: ƒ (a)
overrideMimeType: ƒ (a)
pipe: ƒ ()
progress: ƒ ()
promise: ƒ (a)
readyState: 4
responseJSON: {data: "[{"text":"Home","href":"http://home.com","icon":"f…"fas fa-filter","target":"_self","title":""}]}]}]"}
responseText: "{"data":"[{\"text\":\"Home\",\"href\":\"http:\/\/home.com\",\"icon\":\"fas fa-home\",\"target\":\"_top\",\"title\":\"My Home\"},{\"text\":\"Opcion2\",\"href\":\"\",\"icon\":\"fas fa-chart-bar\",\"target\":\"_self\",\"title\":\"\"},{\"text\":\"Opcion3\",\"href\":\"\",\"icon\":\"fas fa-bell\",\"target\":\"_self\",\"title\":\"\"},{\"text\":\"Opcion4\",\"href\":\"\",\"icon\":\"fas fa-crop\",\"target\":\"_self\",\"title\":\"\"},{\"text\":\"Opcion5\",\"href\":\"\",\"icon\":\"fas fa-flask\",\"target\":\"_self\",\"title\":\"\"},{\"text\":\"Opcion6\",\"href\":\"\",\"icon\":\"fas fa-map-marker\",\"target\":\"_self\",\"title\":\"\"},{\"text\":\"Opcion7\",\"href\":\"\",\"icon\":\"fas fa-search\",\"target\":\"_self\",\"title\":\"\",\"children\":[{\"text\":\"Opcion7-1\",\"href\":\"\",\"icon\":\"fas fa-plug\",\"target\":\"_self\",\"title\":\"\",\"children\":[{\"text\":\"Opcion7-1-1\",\"href\":\"\",\"icon\":\"fas fa-filter\",\"target\":\"_self\",\"title\":\"\"}]}]}]"}"
setRequestHeader: ƒ (a,b)
state: ƒ ()
status: 200
statusCode: ƒ (a)
statusText: "OK"
success: ƒ ()
then: ƒ ()
__proto__: Object
Теперь, как я могу получить responseText значение?