S
S
Sergey2018-04-03 20:51:12
PHP
Sergey, 2018-04-03 20:51:12

Why can't JSON.parse take a string into a json object?

There is an ajax request:
5ac3be7abfb9c033013176.png

And there is an error in the javascript console:
5ac3be8d7c1a2708427940.png

If I replace the "[" and "]" characters with "{" and "}" - I will have exactly the same error.

The string on the backend is generated using json_encode()

Why can't JSON.parse take the string into a json object, what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Archakov Dennis, 2018-04-03
@butteff

The server gives you the left data, instead of an array. You return not only an array, but also a string(92) ... . Fix your backend and only return JSON without extra lines.
You only need to return an array (i.e. not escaped JSON).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question