Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i print JSON with console.log

I am writing a program with php laravel and react.js. But i am very new to these. Anyway in react, i am sending a API request with ajax.

like this:

const sendquery = {
    "async": true,
    "crossDomain": true,
    "url": url,
    "method": "POST",
    "headers": {
        "Authorization": "Bearer " + tkid,
        "Accept": "application/json",
        "Content-Type": "application/json",
    },
    "processData": false,
    "data": query
};

$.ajax(sendquery).done(function (response) {
    console.log('Survey Request :' + response);
});

There are another API requests that are printing nicely when i console.log() because they are in array type. But this must be json. I tested API with Postman everything is OK. But still i have output like this:

Survey Request :[object Object]

Can anyone please help ?

like image 236
Arty Avatar asked Oct 17 '18 09:10

Arty


Video Answer


1 Answers

You can try with JSON.stringify(response) but note that it doesn't work with all the types, see JSON.stringify doesn't work with normal Javascript array, for example.

like image 86
Baris Demiray Avatar answered Nov 08 '22 00:11

Baris Demiray