
Untitled
By: a guest on
Jul 30th, 2012 | syntax:
None | size: 0.65 KB | hits: 9 | expires: Never
Get variable from PHP file using JQuery/AJAX
<?php
$advert = $row[adverts];
?>
<?php
// filename: myAjaxFile.php
// some PHP
$advert = array(
'ajax' => 'Hello world!',
'advert' => $row['adverts'],
);
echo json_encode($advert);
?>
$.ajax({
url : 'myAjaxFile.php',
type : 'POST',
data : data,
dataType : 'json',
success : function (result) {
alert(result['ajax']); // "Hello world!" alerted
console.log(result['advert']) // The value of your php $row['adverts'] will be displayed
},
error : function () {
alert("error");
}
})