Home>Article>Backend Development> php + ajax implement post like function

php + ajax implement post like function

藏色散人
藏色散人 forward
2019-12-17 17:36:50 3425browse

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); ?>      

 
点赞数:

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); } } }) })

PHP code part:

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

For more PHP related knowledge, please visitPHP 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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete