Vlad Nitu Vlad Nitu - 7 months ago 29
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
and I just moved to using JS more than once in a month so I'm still trying to accomodate :)
Thank you!


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.