I have a script where ajax is being used to send password to a PHP file. The PHP file then checks if the password is correct and sends back a data of array with a link and succes code. When the data is received, I can clearly see the keys and values when I alert it, but how do I manipulate the key to get the value from it?
See below for an example how I use to communicate jQuery Ajax with PHP:
jQuery Ajax:
$.ajax({
type: "POST",
url: "test.php",
data: { pass: $("#pass-field").val() }
}).done(function(data) {
if(data.link != ""){
alert("Link: " + data.link);
}
});
PHP:
if(strtolower($retrieved_password) == $original_password){
echo json_encode(array("link" => "personal/cv.doc", "success" => "true"));
}else{
echo json_encode(array("link" => "", "success" => "false"));
}
?>
When I alert data.link I get to see the following code:
function link() {
[native code]
}