Home  >  Article  >  Backend Development  >  php+jQuery+Ajax simply implements asynchronous page refresh_php example

php+jQuery+Ajax simply implements asynchronous page refresh_php example

WBOY
WBOYOriginal
2016-08-17 13:02:321137browse

The page is displayed as follows:

The code in JQueryAjax.html is as follows (using the simpler $.post)




JQueryAjax+PHP


用户名:
密码:


ajax.php

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

In non-json format, the background can only return strings. If you want to return an array in the background, you can use json format

For example, modify the code in JQueryAjax to the following form:




JQueryAjax+PHP


用户名:
密码:

ajax.php

<?php 
$name = $_POST['name'];
$pwd = $_POST['pwd'];
$array = array("$name","$pwd");
//这里进行一个些操作,比如数据库交互

echo json_encode($array);//json_encode方式是必须的
?>

The operation effect is as follows:

The above is the entire content of this article. I hope it will be helpful to everyone’s study. I also hope that everyone will support Script Home.

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