javascript - Json check if certain element has been received -


I have an AJAX call for one of my services that manipulate some databases. The question I am asking for is an easy way to see if I get a certain element in my JSN. For example, I'm receiving {message: "some data message"}, but if there is an error, I want to send back {error: "my error message"}. Is there an easy way to see if an error has been sent? I think the argument is like this (it does not work)

  $ Post ("database.json", {id: id, info: info}) .done (function) {if (data.error) {alert (data.error);} else {alert (data.message); }  

You can see it with

  (Data.hasOwnProperty ("error") {alert (data.error);} else {alert (Data.message);}  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -