Skip to content
Advertisement

Cannot use Json data from ajax response text [closed]

I am working with javascript to fetch data from a database using ajax. The response text is as follows:

JavaScript

I used json_encode($data) on the php script which fetches the data from the MySql database. How do I store the task, category and duration of the response text in separate variables. I cannot use the response obtained. Here is the code:

JavaScript

JavaScript

Advertisement

Answer

Try to declare the type of data received type with dataType : “json”

Like this:

JavaScript

Also your data should be a single json array and not a multiple json object

Try this:

JavaScript

You should have a output like this on console.log

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement