2014-02-04 12:08
浏览 191


This question already has an answer here:

I cant debug this message which appeared like a week ago.

I tried restoring to old files but this is odd, nothing solves my problem.

So: I have two long polling requests. (turning one of them off does not help).

for example this is one of them:

public function update_private_messages_ajax_handler(){
    global $wpdb;
    global $bp;
    $chat_table = $wpdb->prefix . 'bp_dollars_chat';

    $current_user = $bp->loggedin_user->id;

    header("Content-Type: application/json");
    header("Cache-Control: no-cache, must-revalidate");
    header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");

    $startTime = time();
    while((time()-$startTime)<=20) {
        $messages = $wpdb->get_results(
            $wpdb->prepare("(SELECT * 
                FROM $chat_table 
                WHERE to_user = %d
                AND recd = 1
                AND id > %d
                ORDER BY id DESC) ORDER BY id ASC
            ", $current_user, $_POST['last_id'])
        if($messages) {
            foreach($messages as $v){
                //$v->timestring = date_i18n($this->date_format.' - '.$this->time_format, $v->unix_timestamp+$this->gmt_offset);
                $v->name = get_dollar_name($v->from_user);
                $v->avatar = get_avatar($v->from_user, 50);
                //$v->message = convert_smilies( $v->message );
            $response = json_encode(array('no_participation' => $this->no_participation, 'success'=> 1, 'messages'=>$messages));

            echo $response;
            ob_flush(); flush();
        } else {

    $response = json_encode(array('no_participation' => $this->no_participation, 'success'=> 0));

    echo $response;
    ob_flush(); flush();

As you can see, I sent cache-control headers, so this should not be problem described here I also dont have any adBlocker installed and this is local installation.

there is a client-side script

update_private_messages: function() {
    jQuery.post(quick_chat.ajaxurl, {
            action: 'quick-chat-ajax-update-pmessages',
            last_id: quick_chat.last_private_id
        function(data) {
            if(data.success == 1) {
                var updates = data.messages;
                var already_notified = 0;
                var chat_history = jQuery('.popoverx.chat.in .chathistory');
                for(var i=0;typeof(updates[i])!='undefined';i++){
                    // this in case if window open and new message is for current user
                    if(quick_chat.privateOpen == true && (quick_chat.privateOhter == updates[i].from_user || quick_chat.privateOhter == updates[i].to_user )) {
                        // @TODO do I animate every time?
                        jQuery(chat_history).prepend(quick_chat.single_private_html(updates[i])).animate({scrollTop: 0}, 500);
                    } else if(updates[i].recd == 1 && updates[i].from_user != quick_chat.user_id) {
                        // not yet in unread group
                        if(quick_chat.privateUnread.indexOf(parseInt(updates[i].from_user)) == -1) {
                        if(already_notified == 0 && quick_chat.last_private_id != 0 && updates[i].from_user != quick_chat.user_id) {
                            if(quick_chat.play_audio == 1) {
                            already_notified = 1;
                // update label
                var unreadIcon = jQuery('#bs-navbar-right > li > a.messages');
                if(quick_chat.privateUnread.length != 0) {
                    unreadIcon.find('span').remove().end().append('<span class="label label-danger">'+ quick_chat.privateUnread.length +'</span>')
                } else {
                quick_chat.last_private_id = updates[updates.length-1].id;
        }, 'json'

Is this normal? I cant be normal message for long polling - since its a pending request. Its just does not seem to be documented anywhere

Note: also I have many short-polling requests and this could be case where more then 6 requests cancel each other but - I also tried turning all other requests off, except one (long polling) and this is not a case

Here is a original script working so you can see the message: http://www.techytalk.info/wordpress/quick-chat/

Just to summirize this question: Is this normal? (I don't see this problem on other sites where comet is used) - and if not - Where should I seek for problem, clientside or server-side? Here they say that in such case request is not sent at all, but thats not true, my scripts are working and I cant chat (this is a chat script)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • doumanshan6314
    doumanshan6314 2014-02-16 17:45

    This is completely normal in chrome (as of recently). There was a discussion here where they discuss the change, essentially on pending requests it was showing certain headers incorrectly, so now they show a warning that these are provisional headers.

    From the discussion:

    Network Panel: add caution about provisional request headers. (was: In developer tools, request headers for pending requests are incorrect)

    I don't know when the fix actually got released, or if you leave Chrome open all the time and so it didn't update for a while - but almost certainly it is nothing you did - just how Chrome works now.

    点赞 评论
  • duanqian6295
    duanqian6295 2014-02-14 12:35

    Your problem may be the header() coming after the ob_start() function. Try to put the header() before starting the buffer like so:

    header("Content-Type: application/json");
    header("Cache-Control: no-cache, must-revalidate");
    header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
    点赞 评论
  • doulin2947
    doulin2947 2014-03-08 17:31

    This problem can also show up if you forget to do CORS headers in a cross domain call.

     header("Access-Control-Allow-Origin: *");
    点赞 评论
  • doupeizheng3918
    doupeizheng3918 2014-06-05 17:06

    In my case is because the queries return several results that rewrite the session variable in the framework codeigniter. It's in a request AJAX by jQuery.

    Was solved deleted all repeated results.

    点赞 评论