Here's a jQuery-ajax function that returns some data from a php file.
$('.up').click(function() {
var act = $('.active').val();
$.ajax({
type: "POST",
url: "database.php",
data: {
value: act
}
}).done(function(result) {
$('#msg').html(result)
});
});
I get the array result of the query. I have no problem with.
PHP Result :
array(2) {
[0]=> array(2) { ["Label"]=> string(3) "Group1" ["Count"]=> string(1) "244" }
[1]=> array(2) { ["Status"]=> string(7) "Group2" ["Count"]=> string(1) "125" }
}
Actual query result is this.
Label Count
Group1 244
Group2 125
Now that I get the result. I wanted to store the numbers of the Count
column to two different javascript variables.
So far I tried with this.
var value1 = "<?php echo htmlentities($data[0]['Count']) ?>";
var value2 = "<?php echo htmlentities($data[1]['Count']) ?>";
Tried replacing with the above piece of code with result
in the ajax call.
But when I did this the click event itself was not triggered.
I've saved the numbers to two php
variables namely value1
and value2
.
And in the result of the ajax
call i get the result like 244125
.
Help me saving that number to two different javascript
variables.