ajax-php总结

来源:互联网 发布:yum y什么意思 编辑:程序博客网 时间:2024/06/06 01:35

一、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']}\"}]" 
?>

0 0
原创粉丝点击