Vlad Nitu Vlad Nitu - 5 months ago 13
Ajax Question

JavaScript use object content

I'm trying to separate some values that come from an AJAX request.

They look like this:

Object { name: "fsdfsd", details: "sdfsdf", password: "sdfsdgds" }


And I'd basically need them separated each value in its variable. How can I do that?

I've searched around but can't find a good answer. I'm used to PHP syntax like
$this->output
and I just moved to using JS more than once in a month so I'm still trying to accomodate :)
Thank you!

Answer

Try this:

var res = { name: "fsdfsd", details: "sdfsdf", password: "sdfsdgds" };
var name = res.name;
var details = res.details;
var password = res.password;

But I strongly recommend you to use res as object. You could use less number of variables and have less potential problems. AND DON'T SEND PASSWORD AS A PLAIN TEXT! Someone can listen your traffic and dump all your users passwords.

Comments