Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php fancybox关闭时的Ajax刷新_Php_Sql_Ajax_Fancybox - Fatal编程技术网

Php fancybox关闭时的Ajax刷新

Php fancybox关闭时的Ajax刷新,php,sql,ajax,fancybox,Php,Sql,Ajax,Fancybox,我有一个div的内容是这样生成的 <div class="messagecount"> <?php $mesagecount = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM " . $wpdb->base_prefix . "messages WHERE message_to_user_ID = %d", $user_ID)); echo $messagecount; ?> </div&g

我有一个div的内容是这样生成的

<div class="messagecount">
<?php
$mesagecount = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM " . $wpdb->base_prefix . "messages WHERE message_to_user_ID = %d", $user_ID));
echo $messagecount;
?>
</div>
我还使用fancybox弹出一条消息,我设置了回调,这样当我关闭fancybox时,我可以调用一个命令,但现在我希望能够在不刷新页面的情况下刷新messagecount div

我可以使用ajax结合fancybox关闭回调来实现这一点吗?

可以。 首先,分配给您的div id messagecount。 然后,在文档的标题部分输入以下代码:

<script>
function ajaxRequest(){
 var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"]
 if (window.ActiveXObject){
  for (var i=0; i<activexmodes.length; i++){
   try{
    return new ActiveXObject(activexmodes[i])
   }
   catch(e){
   }
  }
 }
 else if (window.XMLHttpRequest)
  return new XMLHttpRequest()
 else
  return false
}
</script>
现在,创建load.php并将其放入:

<?php
$mesagecount = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM " . $wpdb->base_prefix . "messages WHERE message_to_user_ID = %d", $user_ID));
echo $messagecount;
?>
要重新加载长方体,只需在其后面添加以下代码:

<a href="#"  onclick="sending(); return false;">Reload</a>
<script>
    function sending(){
    document.getElementById("messagecount").innerHTML="Refreshing"
    var mypostrequest=new ajaxRequest()
    mypostrequest.onreadystatechange=function(){
     if (mypostrequest.readyState==4){
      if (mypostrequest.status==200 || window.location.href.indexOf("http")==-1){
       document.getElementById("messagecount").innerHTML=mypostrequest.responseText
      }
      else{
       document.getElementById("messagecount").innerHTML='Woops! An error occurred. Please check your Internet connection and try again.';
      }
     }
    }
    mypostrequest.open("GET", "load.php", true)
    mypostrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
    }
</script>

当然你可以,如果你使用的是我认为你实际上是ajax调用的话,你的ajax调用和fancybox都可以。。。你试过什么?信息在哪里?更新消息计数div的信息?