I am trying to learn the Jquery AJAX function but am struggling to work out how to pass PHP variables into my main document.
This is what I currently have:
<script>
var refreshId = setInterval(function() {
$.ajax({
url: "test.php",
dataType: "json", //the return type data is jsonn
success: function(data){ // <--- (data) is in json format
$('#testdiv').html(data.test1);
$('#testdiv').append(html(data.test2));
//parse the json data
}
});
}, 1000);
</script>
getJSONon api.jquery.com. And use the PHP method json_encode to encode and send the data back to youjson_encodeon the PHP side and a json call on the JS sidehtml(data.test2)instead just try$('#testdiv').html($('#testdiv').html() + data.test2);