Skip to content
Advertisement

Need help to debug json response

I am trying to sent response in that form

JavaScript

But I’m getting response like that

JavaScript

Here is my PHP code:

JavaScript

Please help me to fix code i need response in that way

JavaScript

Advertisement

Answer

You should no do $val = '{"files":['.$enc.']}';

Use json_encode to make json, don’t do it manual


  1. Create an object with desired keys outside the loop
  2. Push anything to the desired array
  3. Convert to json
JavaScript

If I use some dummy values to create an example, the output is:

JavaScript

As you can test in this online demo

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