Skip to content
Advertisement

how to access specific elements from a promise

in php I return to javascript the following:

JavaScript

in my js file I have:

JavaScript

this writes out to the console:

JavaScript

how do I access the value ‘FOUND’ associated with the key ’email’? I’ve tried response[’email’], response.email and response[0][’email’]

Advertisement

Answer

The title is very misleading because the problem is completely unrelated to promises.

The backend doesn’t provide pure JSON but HTML containing JSON. There are two ways to approach this problem. The first approach is to print pure JSON without HTML in PHP.

JavaScript

The second approach is to parse the HTML, read the node and parse it as JSON:

JavaScript

Of course, I prefer the first approach if possible.

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