Answer the question
In order to leave comments, you need to log in
How to parse server response after $ajax() request?
I send the request like this:
function send() {
var uri = 'http://127.0.0.1:5000/todo/api/v1.0/tasks';
var method = 'GET'
var request = {
url: uri,
type: method,
contentType: "application/json",
accepts: "application/json",
cache: false,
dataType: 'json',
};
return $.ajax(request);
};
{readyState: 1, getResponseHeader: ƒ, getAllResponseHeaders: ƒ, setRequestHeader: ƒ, overrideMimeType: ƒ, …}abort: ƒ ( statusText )always: ƒ ()complete: ƒ ()done: ƒ ()error: ƒ ()fail: ƒ ()getAllResponseHeaders: ƒ ()getResponseHeader: ƒ ( key )overrideMimeType: ƒ ( type )pipe: ƒ ( /* fnDone, fnFail, fnProgress */ )progress: ƒ ()promise: ƒ ( obj )readyState: 4responseText: "{↵ "tasks": [↵ {↵ "title": "Buy groceries",↵ "description": "Milk, Cheese, Pizza, Fruit, Tylenol",↵ "done": false,↵ "uri": "/todo/api/v1.0/tasks/1"↵ },↵ {↵ "title": "Learn Python",↵ "description": "Need to find a good Python tutorial on the web",↵ "done": false,↵ "uri": "/todo/api/v1.0/tasks/2"↵ }↵ ]↵}↵"setRequestHeader: ƒ ( name, value )state: ƒ ()status: 200statusCode: ƒ ( map )statusText: "OK"success: ƒ ()then: ƒ ( /* fnDone, fnFail, fnProgress */ )__proto__: Object
{
"tasks": [
{
"title": "Buy groceries",
"description": "Milk, Cheese, Pizza, Fruit, Tylenol",
"done": false,
"uri": "/todo/api/v1.0/tasks/1"
},
{
"title": "Learn Python",
"description": "Need to find a good Python tutorial on the web",
"done": false,
"uri": "/todo/api/v1.0/tasks/2"
}
]
}
Answer the question
In order to leave comments, you need to log in
Can be even easier
var uri = 'http://127.0.0.1:5000/todo/api/v1.0/tasks';
$.get(uri, function (data) {
console.log('data from server --- ', data);
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question