I am having the hardest time parsing the response from an ajax request correctly. I have an ajax request that gets back a json array, all I need to do is parse it correctly so I get my two values out.
On the php side, I create the array like so:
while($row = $result->fetch_assoc()) {
$response[]=array("value" => $row["uid"], "text" => $row["value"]);
}
My array in PHP looks like this when I print_r:
Array ( [0] => Array ( [value] => 6 [text] => 40 ) [1] => Array ( [value] => 7 [text] => 48 ) )
I then json_encode that array and send it back via ajax. Here is my ajax call:
$.ajax({
type: 'GET',
url: 'ajax.php?s='+selection,
dataType: 'json',
success: function (data) {
$.each( data, function( intValue, currentElement ) {
$.each(currentElement, function( key, value ) {
console.log(key);
console.log(value);
});
});
}
});
I would have thought console.log(key) would show 6 and console.log(value) would show 40 but instead I get:
value
6
text
40
value
7
text
48
I really need help just getting 6 and 40 then 7 and 48 (based on array provided).
I have tried a bunch of ways, nothing seems to work.