Skip to content
Advertisement

Jquery – Uncaught TypeError: Cannot use ‘in’ operator to search for ‘324’ in

I’m trying to send a Get request by ajax and output json data that is returned by server in html.

But, I got this error.

JavaScript

This is my code that sends a Get request to php file by ajax. When I use $.each method, it get the error that I showed in the above.

JavaScript

This is my PHP code that returns query result in json format.

JavaScript

json data outputted by this php is like this.

JavaScript

Anyone knows how to fix this problem?

Please help me out. Thanks in advance 🙂

Advertisement

Answer

You have a JSON string, not an object. Tell jQuery that you expect a JSON response and it will parse it for you. Either use $.getJSON instead of $.get, or pass the dataType argument to $.get:

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