我试图在 php 数据成功发送到服务器后显示成功 div,仅更新但 div 未显示。
有人可以告诉我哪里出了问题吗?我查看了堆栈溢出并尝试了许多不同的解决方案,但没有成功。
<div id= "infomsg" style="display: none;">Updated Successfully! </div>
$.ajax({
type: "POST",
url: "validate.php",
cache: false,
dataType: "json",
data: dataString,
success: function(Success){
$('#infomsg').show(Success)
}
});
if (isset($_POST))
{
$first=$_POST['first'];
$middle=$_POST['middle'];
$last=$_POST['last'];
$email=$_POST['email'];
$lives=$_POST['lives'];
$Gender=$_POST['Gender'];
$about=$_POST['about'];
$fav_track=$_POST['fav_track'];
$fav_bands=$_POST['fav_bands'];
$sql3 = "UPDATE user SET first='$first',middle='$middle',last='$last',email='$email',lives='$lives',Gender='$Gender', about='$about', fav_track='$fav_track', fav_bands='$fav_bands' WHERE `id`='".$_SESSION['id']."'";
$res3 = mysqli_query($mysqli,$sql3) or die(mysqli_error($mysqli));
//Writes the photo to the server
if($res3)
{
//Tells you if its all ok
echo '<div id= "infomsg" style="display: none;">Updated Successfully! </div>';
}else{
//Gives and error if its not
echo "Sorry, there was a problem updating the Information, Contact <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7b081e4c1e09153b081e4c1e0915551814550e10" rel="noreferrer noopener nofollow">[email protected]</a> with REF:#1112-Validate.";
}
}
最佳答案
如果您只想显示 <div>
您不必在“show()
”方法中传递任何参数。
您可以使用下面提到的方法来做到这一点:
<div id="infomsg" style="display: none;">Updated Successfully!</div>
$.ajax({
type: "POST",
url: "validate.php",
cache: false,
dataType: "json",
data: dataString,
success: function (Success) {
$('#infomsg').show();
}
});
关于php - 成功响应时显示 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24453134/