所以基本上我使用Ajax脚本将数据插入到我的数据库中,但是 当我在没有重新加载的情况下发布我必须在同一文件中使用的数据时,它会被执行但文件中没有任何反应,只是数据库插入完成。
$( document ).ready(function() {
$("input#sbm").click(function(){
$.ajax({
//url: '', // url is empty because I'm working in the same file
data: $('form#ddb').serialize(),
type: 'POST',
success: function(result) {
alert("<?php echo "https://example.com/".$id; ?>");
}
});
});
});
我试图回显链接,但是没有设置$ id,但是数据库条目已经生效了!那么我如何在没有重新加载的情况下在文件中使用php代码,或者是否有任何可能的方法从我发送的文件中获取数据,因为我在我的页面上确定需要$ id变量btw它是https://viid.su
if(isset($user["id"]))
{
$uid = $user["id"];
}
else {
$uid = 0;
}
$flink = $_POST['url'];
$re = '/^(?:https?\:\/\/)?[a-z0-9\-_]+\.[a-z0-9\-_\.\/%&=\?\+]+$/mi';
$re2 = '/^[a-zA-Z]+[:\/\/]+[A-Za-z0-9\-_]+\\.+[A-Za-z0-9\.\/%&=\?\-_]+$/i';
if (!preg_match($re2, $flink, $matches, PREG_OFFSET_CAPTURE, 0)){
$flink = "http://". $flink; }
if(preg_match($re, $flink, $matches, PREG_OFFSET_CAPTURE, 0)){
$db = mysqli_connect($host, $username, $password);
$conn = new mysqli($host, $username, $password, $database);
$id = substr(str_shuffle(str_repeat("aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxYyYzZ", 5)), 0, 5);
if($conn->query("INSERT INTO `".$database."`.`link` (`id`, `flink`,`adonly`,`userid`) VALUES ('".$id."', '".$flink."','true','".$uid."');")) {
$html = 'Your short URL is <a class="test" href="https://viid.su/'.$id.'">https://viid.su/'.$id.'</a>';
echo $html;
} else {
}
mysqli_close($db);
}
elseif(isset($_POST['url'])){
$html = "THAT'S AN INVALID URL!";
}
php代码只是用于测试,我知道我需要做很多事情并进行编辑,但我仍然希望你们只是帮助我解决我所描述的问题:)