I'm trying to access individual elements of my JSON that I've returned from a .post method with jQuery. When I send the data to create.php, all it does is json_encode the data and put it in a json object. Here is my code:
$.post("pages/create.php", {user : "user1", password : "pass2"}, function(data) {
var newArray = new Array();
newArray = {"user":"user2","password":"pass2"};
console.log(newArray.user);
console.log(data);
console.log(data.user);
The issue is that the first two console logs do what I would expect. The first one gives me:
"user2"
The second gives me:
"user" : "user1", "password" : "pass2"
But the third is undefined, even though I know the data JSON object has stuff in it. Is my syntax wrong? I'm just trying to access a specific element of that JSON.