Home  >  Article  >  php教程  >  php+jquery+ajax初体验

php+jquery+ajax初体验

WBOY
WBOYOriginal
2016-06-21 08:46:201023browse

这个一个简单的php与ajax案例 仅供新手学习

附上效果图




jquery ajax代码

 $(function(){   $("#send").click(function(){    var cont = $("input").serialize();    $.ajax({     url:'aseoe.php',     type:'post',     dataType:'json',     data:cont,     success:function(data){      var str = data.username + data.age + data.job;      $("#result").html(str);     }    });   });    });
php接收数据

//php ajax 初体验  header("Content-type:text/html;charset=utf-8"); $username = $_POST['username']; $age = $_POST['age']; $job = $_POST['job']; $json_arr = array("username"=>$username,"age"=>$age,"job"=>$job); $json_obj = json_encode($json_arr); echo $json_obj; ?>
更多php+ajax实例,关注爱思资源网



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn