I would like to know how to get a PHP array field value from a PHP file using jquery/Ajax. In fact, I have three files: mapage.html , moslem.php and moslem1.php . You find below the code of each file.
The code of mapage.html:
<script type="text/javascript">
$(document).ready(function() {
setTimeout( test, 1000);
});
function test() {
$.ajax({
url: 'moslem.php',
type: 'POST',
success: function(data) {
var max;
max = data;
setTimeout( test1, 500);
function test1() {
$.ajax({
url: 'moslem1.php',
type: 'POST',
success: function(data1) {
document.write(data1+"<br>");
}
});
}
}
});
setTimeout( test, 1000);
}
The code of moslem.php :
<?php
$con=mysqli_connect("localhost","root","","test");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM jqcalendar ORDER BY id DESC LIMIT 0, 1");
while($row = mysqli_fetch_array($result)) {
$max=$row['Id'];
}
echo $max;
mysqli_close($con);
?>
The code of moslem1.php :
<?php
$con = mysqli_connect("localhost", "root", "", "test");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con, "SELECT * FROM jqcalendar ORDER BY id DESC LIMIT 0, 1");
while ($row = mysqli_fetch_array($result)) {
$notification = array('id' => $row['Id'], 'subject' => $row['Subject'], 'location' => $row['Location'], 'description' => $row['Description'], 'starttime' => $row['StartTime'], 'endtime' => $row['EndTime']);
}
print_r($notification);
mysqli_close($con);
?>
Well, when I run the file mapage.html, it displays the below line every one second :
Array ( [id] => 22 [subject] => reading books [location] => at home [description] => reading some books. [starttime] => 2014-05-21 11:00:00 [endtime] => 2014-05-21 12:00:00 )
So as you can notice above it displays the content of the array "notification" which exist in the code of moslem1.php. Now, my question is how can I modify the line below to display just a field value of that array (for example the value of the filed "subject" or any other field):
document.write(data1+"<br>");
Thanks in advance.