php + ajax implement post like function

藏色散人
Release: 2023-04-08 06:20:02
forward
3323 people have browsed it

Knowledge:

1. First, the page needs to load the jquery framework

2. Explanation of common ajax parameters:

①, type: data transmission method, get or post

②. url: PHP script that processes data

③. data: transmitted data index and value. The value is obtained with js. Generally, this attribute is a json string or string

④, async: The parameter is a Boolean type, the default is true, that is, asynchronous transmission, the browser is not locked

⑤, complete: The parameter is a method, the callback function after the jump script execution is completed

⑥, success: The parameter is a method, the callback function after the jump script is successfully executed

⑦, error: The parameter is a method, the callback function after the jump script fails to execute

3. After the script processing is completed, return the data required by the page, and then implement partial refresh on the front-end page according to the needs instead of jump refresh. This is the most powerful place of ajax

html code part:

GetOneData($sql);
 
 
 
?>







 
点赞数:
Copy after login

js code:

$("#btn").click(function(){
$.ajax({
url:"index.php",
type:"POST",
data:{id:},
async:false,
success:function(data){
if(data === false){
alert('点赞失败!');location.href='dianzan.php?id=';
}else{
alert('点赞成功!');$("#s").html(data);
}
}
})
})
Copy after login

PHP code part:

execSql($sql);
if($res){
$dz = $db->getOneData("select * from news where id = '$id'");
$dz = $dz['dianzan'];
echo $dz;
}else{
return false;
}
 
 
 
 
?>
Copy after login

For more PHP related knowledge, please visit PHP Tutorial!

The above is the detailed content of php + ajax implement post like function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:csdn.net
Statement of this Website
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 [email protected]
Latest issues
Popular Tutorials
More>
Latest downloads
More>
web effects
Website source code
Website materials
Front end template
About us Disclaimer Sitemap
PHP Chinese website:Public welfare online PHP training,Help PHP learners grow quickly!