一、ajax与PHP交互
注意:[{},{},{}]是json数组
1、ajax
$(function(){
$('#send').click(function() {
$.ajax({
type: "GET",
url: "ajax3.php",
data:{"a":"b","b":"a"},
dataType: "json",
success : function(data){
alert(data.length);
}
});
});
})
2、ajax3.php
<?php
header("Content-Type:text/html; charset=utf-8");
echo "[{ \"username\" : \"{$_REQUEST['a']}\" , \"content\" : \"{$_REQUEST['b']}\"},{ \"username\" : \"{$_REQUEST['a']}\" , \"content\" : \"{$_REQUEST['b']}\"}]"
?>