rest - Extracting data from json in JavaScript -


i have ajax connection controller

function changeemail() {     $.ajax({         ...         contenttype: "application/json",         datatype: "json",         ...         error: function (error) {             var obj = error.responsetext;             console.log('error: ' + obj);             console.log('obj length: ' +  obj.fielderrors.length);         }     }); } 

which in case of error returns list of errors in json. however, not able refer list. https://zapodaj.net/e6354b8c71f4c.png.html not know, example, how refer first element of list

message

variable

depending on content-type response server, default response type text/html or other incorrect content-type.

you have 2 ways fix this. first, can set obj = json.parse(error.responsetext)

or, can make sure server sets correct content-type on errors well.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -