您的位置:首页 > 编程语言 > PHP开发

ajax-php总结

2015-08-20 16:29 627 查看
一、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']}\"}]" 

?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: