Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax request and my Symfony 1.4 Response : Contents doesn't match

I'm using jQuery for my ajax request and Symfony 1.4 PHP in server side.

My problem is in the title.

How to reproduce :

I have a footer (in all my pages) to display Tweets of my web site who have a kind of "keep alive call" to get last Tweets every 7s.

function loadNotyTweets(tweetCount) {

    var jqXhr = $.ajax({
        'url':'<?php echo url_for(array('module' => 'footer', 'action' => 'getLastApiTweets')) ?>',
        'type':'GET',
        'async':true,
        'dataType':'json',
        'cache': false
    }).done(function (data, textStatus, jqXHR) {
        if (data != null) {
            var j = 0;
            for (var i in data) {
                var text = formatNoty(data[i]['text'], data[i]['user']['screen_name'], data[i]['user']['name'], data[i]['user']['profile_image_url_https'], data[i]['created_at']),
                    hashTweet = calcMD5(text);

                if (!$.cookie(hashTweet) || $.cookie(hashTweet) != 'close') {
                    // Display a noty containing my tweet
                    generateNoty(text);
                }
                j++;
                if (j == tweetCount) {
                    break;
                }
            }
        }
    });

}

And in server side :

function executeGetLastApiTweets(sfWebRequest $request) {
        if ($request->isXmlHttpRequest()) {

            // Get tweet using Twitter API
            $tweets = $this->getApiTweets($request);

            $lastTweet = '';
            if (isset($tweets[0]) && isset($tweets[0]['text'])) {
                $lastTweet = md5($tweets[0]['text']);
            }

            if ($this->isLastTweet($lastTweet)) {
                return $this->renderText(json_encode($this->getTweetsUI($tweets)));
            }

        }
        return sfView::NONE;
    }

Now, when I click on my web site on a link (just after my loadTweets() is calling) I get the response of this Ajax call instead of the response of the link i click.

I have no idea of what appenning here...

For info :

I've my Apache deflate compression active. I think it could come from this.

There is, my Apache Conf.

    # MOD_DEFLATE COMPRESSION
    SetOutputFilter DEFLATE
    AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application/x-javascript application/x-httpd-php
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
    Header append Vary User-Agent env=!dont-vary

    # BEGIN Expire headers
    <IfModule mod_expires.c>
     ExpiresActive On
     ExpiresDefault "access plus 7200 seconds"
     ExpiresByType image/jpg "access plus 1 days"
     ExpiresByType image/jpeg "access plus 1 days"
     ExpiresByType image/png "access plus 1 days"
     ExpiresByType image/gif "access plus 1 days"
     AddType image/x-icon .ico
     ExpiresByType image/ico "access plus 7 days"
     ExpiresByType image/icon "access plus 7 days"
     ExpiresByType image/x-icon "access plus 7 days "
     ExpiresByType text/css "access plus 7 days"
     ExpiresByType text/javascript "access plus 7 days"
     ExpiresByType text/html "access plus 7200 seconds"
     ExpiresByType application/xhtml+xml "access plus 7200 seconds"
     ExpiresByType application/javascript "access plus 7 days"
     ExpiresByType application/x-javascript "access plus 7 days"
     ExpiresByType application/x-shockwave-flash "access plus 1 days"
    </IfModule>
    # END Expire headers
# BEGIN Cache-Control Headers
<IfModule mod_headers.c>
 <FilesMatch "\\.(ico|jpe?g|png|gif|swf|gz|ttf)$">
   Header set Cache-Control "max-age=86400, public"
 </FilesMatch>
 <FilesMatch "\\.(css)$">
   Header set Cache-Control "max-age=604800, public"
 </FilesMatch>
 <FilesMatch "\\.(js)$">
   Header set Cache-Control "max-age=604800, public"
 </FilesMatch>
 <filesMatch "\\.(html|htm)$">
   Header set Cache-Control "max-age=7200, public"
 </filesMatch>
 # Disable caching for scripts and other dynamic files
 <FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$">
   Header unset Cache-Control
 </FilesMatch>
</IfModule>
# END Cache-Control Headers

# KILL THEM ETAGS
Header unset ETag
FileETag none
like image 483
Jonathan Masmejean Avatar asked Nov 03 '22 10:11

Jonathan Masmejean


1 Answers

You declared your ajax variable as:

var jqXhr = $.ajax({

Then you reference your variable as:

}).done(function (data, textStatus, jqXHR) {

Correct me if I'm wrong, javascript/jquery variables are case-sensitive.

like image 52
wesleywmd Avatar answered Nov 11 '22 08:11

wesleywmd