Hello.

I'm trying to display the results of an Ajax query:

... success: function(data) { alert(data); } ... 

Everything is normal output {"error": "You forgot to specify the link."}

I try to display a separate value:

 alert(data.error); 

Displays: undefined

I tried this:

 var arr = new Array(); arr = data; alert(arr.error); 

The result is the same.

Actually, please explain what the problem is.

    1 answer 1

    Your server does not give the data in JSON format, but in the usual line. It is necessary either to convert to an object, or to give data with the title application/json

     success: function(data) { var errors = JSON.parse(data); alert(errors.error); } 
    • Works. Thank! - lightcyber