0

我这里有问题。成功将数据保存到mysql后,我尝试使用DIV显示信息框。

这是我的短代码。

// Mysql插入过程

if($result){?>
    <script type="text/javascript">
        $(function() {  
        $.ajax({
        $('#info').fadeIn(1000).delay(5000).fadeOut(1000)
        $('#infomsg').html('Success.')
            });
    }
    </script>
<?php }

DIV怎么会出现?我试过了,但什么也没出现。有什么帮助吗?谢谢

4

2 回答 2

0

一个基本的 jQuery ajax 请求:

$(function() {  
    $.ajax({
        url: "the url you want to send your request to",
        success: function() {
            //something you want to do upon success
        }
    });
}
于 2013-08-14T02:02:30.120 回答
0

假设您有一个 ID 会话,并且您想在数据库中检索它。

这里是:info.php

 <input type="hidden" name="id"><input>
 <input type="submit" onclick="showResult(id)" value="Click to Show Result"></input>
 function showResult(id){
 $j.ajax(
      method:"POST",
      url:"example.php",
      data: {userid:id},
      sucess: function(success){
    $('#infomsg').html(Success)
        });
  }
  <div id= "infomsg"></div>

例子.php

$id = $_POST['userid']; ///////from the data:{userid :id}

//////////config of your db
$sql = mysql_query("select * from users where id = $id");
foreach ($sql as $sq){
echo $sq['id']."<br>";
}

“infomsg”将从函数成功中获取结果并将其放入 div。

于 2013-08-14T04:12:54.550 回答