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:
<?php $id = $_GET['id']; require_once 'mysqlHelper.php'; $db = new mysqlHelper('localhost','root','root','dianzan'); $sql = "select * from news where id = '$id'"; $news = $db->GetOneData($sql); ?> <!doctype html> <html> <head> <script src="jquery-1.9.1.min.js"></script> <meta charset="UTF-8"> </head> <body> <h1><?php echo $news['title'];?></h1> <pre class="brush:php;toolbar:false"> <?php echo $news['content'];?>点赞数: