php - 成功响应时显示 div

标签 php jquery html ajax

我试图在 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/

相关文章:

javascript - 从 javascript 制作超链接

android - Android 上是否有 "add to homescreen"webapp(就像在 iOS 中一样)

php - 不能将 stdClass 类型的对象用作数组

php - 在 CodeIgniter 上向 OR_LIKE 查询添加括号

php - 如何?通过 jQuery.ajax :POST and using php: file_put_contents(); 从 CodeMirror 编辑器发送 PHP 代码

javascript - jQuery slideUp/Down 淡入/淡出不对称

javascript - 图片内存游戏

php - 将项目从 windows-1256 转换为 utf-8 字符集,正确的步骤是什么?

javascript - JQuery 绑定(bind)在循环中出错

javascript - 使用 javascript queryselectorall 而不是 jquery 选择器