We can do this usgin jquery. There are 2 methods.
.getJSON()
Example:
<?php echo json_encode(array("a" => "valueA", "b" => "valueB")); ?>
In Javascript:
$.getJSON("myscript.php", function(data) {
alert("Value for 'a': " + data.a + "\nValue for 'b': " + data.b);
});
.ajax()
$.ajax ({
type: "POST",
url: "customerfilter.php",
dataType: json,
cache: false,
success: function(data)
{ $(".custName").html(data.message1);
$(".custName2").html(data.message2);
} });
Then you need to encode your response as a JSON Array:
<?php echo json_encode( array("message1" => "Hi", "message2" => "Something else") ) ?>
No comments:
Post a Comment