栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何从ajax调用php函数?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何从ajax调用php函数?

对于ajax请求

1.在您的网页中包含Jquery库。例如:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

2.点击按钮调用功能

<button type="button" onclick="create()">Click Me</button>

3.点击按钮,调用Javascript创建函数。

    <script>    function create () {          $.ajax({ url:"test.php", //the page containing php script type: "post", //request type, dataType: 'json',data: {registration: "success", name: "xyz", email: "abc@gmail.com"} success:function(result){  console.log(result.abc);}         });     }<script>

在服务器端的test.php文件中,应读取action POST参数和相应的值,并以php格式执行操作并以json格式返回,例如

$regstration = $_POST['registration'];$name= $_POST['name'];$email= $_POST['email'];if ($registration == "success"){ // some action goes here under php echo json_enpre(array("abc"=>'successfuly registered'));}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/398049.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号