如果我使用ajax和jquery从数据库中查看内容,这将在幕后发生。好的 ?但是如果我想使用ajax,jquery并在url中进行更改。怎么会发生这种情况? 例如:我正在网站上查看新闻,我如何为用户访问或共享的每条新闻创建一个唯一的网址,虽然它在幕后工作?
AJAX
$(document).ready(function(){
$(document).on('click','#see',function(){
var ID = $("#rowid").val();
var er = "_|_";
$.ajax({
type:'POST',
url:'news.php',
data:'var='+ID,
success:function(response){
// history.pushState('data', '', 'news.php?var='+ID);
window.location.href = "news.php?var="+ID;
}
});
});
});
PHP
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="script.js"></script>
<?php
error_reporting(0);
include("../icac/includes/db-connect.php");
mysqli_query($con,"set names 'utf8'");
$query="SELECT * FROM `icac_content_tbl` LIMIT 1";
$result= mysqli_query($con,$query);
while($row=mysqli_fetch_array($result)){ ?>
<h1><input id="rowid" type="hidden" value="<?php echo $row["content_title"]; ?>"/></h1>
<a href="javascript:void(0)" id="see">see link</a>
<h2><?php if( $row["content_title"] == $_GET["var"]) { echo $row["content_title"];
echo "<br>"; echo $row["content_body"];
;} ?></h2>
<?php
}
?>