首页 > 编程 > PHP > 正文

通过php+JQuery+Ajax简单实现页面异步刷新的代码案例

2020-03-22 17:49:15
字体:
来源:转载
供稿:网友
页面显示如下:

JQueryhtml' target='_blank'>Ajax.html中的代码如下(用的较为简单的$.post)


 html  head  meta charset= UTF-8  title JQueryAjax+PHP /title  script type= text/javascript src= http://code.jquery.com/jquery-3.0.0.min.js /script  /head  body  用户名: input type= text id= username name= username / br  密码: input type= password id= password name= password / br  button type= button >

ajax.php:

ajax.php ?php echo 用户名: ,$_POST[ name ], ,密码: ,$_POST[ pwd ]. br //这里可以进行一些操作,比如数据库交互
echo 操作完毕 ?

在非json格式下,后台只能返回字符串,如果想后台返回数组,可以采用json格式

例如将JQueryAjax中的代码修改为如下形式:

 html  head  meta charset= UTF-8  title JQueryAjax+PHP /title  script type= text/javascript src= http://code.jquery.com/jquery-3.0.0.min.js /script  /head  body  用户名: input type= text id= username name= username / br  密码: input type= password id= password name= password / br  button type= button >

ajax.php

 ?php $name = $_POST[ name $pwd = $_POST[ pwd $array = array( $name , $pwd //这里进行一个些操作,比如数据库交互echo json_encode($array);//json_encode方式是必须的? 

运行效果如下:


本文讲解了通过php+JQuery+Ajax简单实现页面异步刷新的代码案例,更多相关内容请关注php 。

相关推荐:

thinkphp+redis+队列相关问题

服务器上搭建一个lamp(Linux(CentOS7)+Apache+MySQL+PHP)

Android+PHP+MYSQL开发简单实例的讲解

以上就是通过php+JQuery+Ajax简单实现页面异步刷新的代码案例的详细内容,PHP教程

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表