Ich benutze jQuery für meine Ajax-Anfrage und Symfony 1.4 PHP in Serverseite.Ajax-Anfrage und meine Symfony 1.4 Antwort: Inhalt passt nicht
Mein Problem ist im Titel.
Wie zu reproduzieren:
Ich habe eine Fußzeile (in all meinen Seiten) Tweets meiner Website angezeigt werden, die eine Art „am Leben halten Ruf“ hat all 7s letzte Tweets zu bekommen.
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;
}
}
}
});
}
Und in Server-Seite:
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;
}
Nun, wenn ich auf einen Link auf meiner Website klicken (nur nach meinem loadTweets() ruft) Ich habe die Antwort des Ajax-Aufruf erhalten statt der Antwort des Links klicke ich.
Ich habe keine Ahnung von dem, was hier appenning ...
Für Informationen:
ich meine Apache Kompression aktiv abzulassen haben. Ich denke, es könnte daraus entstehen.
Es gibt meine 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
Haben Sie versucht, einige Apache-Einstellungen zu ändern? Es scheint ein Problem mit Apache zu sein. Ich denke nicht, dass es eine Möglichkeit gibt, PHP oder Symfony könnte sich mit zwei verschiedenen Anfragen auf diese Weise anlegen. Oder vielleicht ist es ein Problem mit Ihrem JS und Links. Haben Sie überprüft, ob beim Klicken auf einen Link die Anfrage an die richtige URL gesendet wird? –
Es kann nicht von meinem JS kommen. Meine Links sind HTML-Links ohne "on-click" jQuery Events Binded. Ich denke, dass es von meinen Apache-Einstellungen kommen kann, aber es ist komisch! Wie könnte es sein ? Was kann mit meiner Apache-Konfiguration falsch sein? –
Aber haben Sie das überprüft? Öffne Firebug, Fiddler oder ähnliches. Sie können bei jeder Anfrage, die Sie über den Browser vornehmen, prüfen. Yuo kann sehen, welche URL aufgerufen wird und was Sie als Antwort erhalten. Wenn Sie sicher sind, dass Sie die richtige Seite aufrufen und die falsche Antwort erhalten, können Sie sich vorstellen, was mit dem Apache nicht stimmt. –