Ho il codice che fa una semplice richiesta di ottenere su Twitter (ricerca) usando il metodo Ajax di jQuery. Il codice funziona bene su Safari, ma non funziona su Firefox (3.6.3). Nel caso di Firefox, viene invocato il metodo "success" dei miei parametri jQuery.ajax
, ma i dati forniti sono nulli. (. In Safari, ricevo un sacco di dati JSON)jQuery.ajax chiama su Twitter ma restituisce null per Firefox
mia chiamata Ajax è:
$.ajax({
url: 'http://search.twitter.com/search.json?q='+searchTerm,
dataType: 'json',
async: true,
beforeSend: function(request) {
window.console.log('starting AJAX request to get Twitter data');
},
success: function(data, textStatus, request) {
window.console.log('AJAX request to get Twitter succeeded: status=' + textStatus);
callback(data);
},
error: function(request, status, error) {
window.console.log('Ajax request to get user data --> Error: ' + status);
errback(request, status, error);
}
});
Firebug mostra le intestazioni di risposta:
statoDate Sun, 11 Apr 2010 22:30:26 GMT
Server hi
Status 200 OK
X-Served-From b021
X-Runtime 0.23841
Content-Type application/json; charset=utf-8
X-Served-By sjc1o024.prod.twitter.com
X-Timeline-Cache-Hit Miss
Cache-Control max-age=15, must-revalidate, max-age=300
Expires Sun, 11 Apr 2010 22:35:26 GMT
Vary Accept-Encoding
X-Varnish 1827846877
Age 0
Via 1.1 varnish
X-Cache-Svr sjc1o024.prod.twitter.com
X-Cache MISS
Content-Encoding gzip
Content-Length 2126
Connection close
Il HTTP è OK (200), il Content-Type è correttamente application/json
e il Content-Length di 2126 (gzip'd) implica il ritorno dei dati. Tuttavia, Firebug indica che la risposta è vuota e un test dei dati forniti mostra che è "null".
Sono consapevole di un post simile su Stack Overflow, jQuery $.get() function succeeds with 200 but returns no content in Firefox e da quel potrebbe supporre questo problema è possibilmente correlati alla sicurezza cross-domain, ma ... so che ci sono molti widget JavaScript e quant'altro che ottengono Ajax dati da Twitter. C'è qualcosa che devo abilitare per consentire questo?
Ah, sicuramente è un problema con i criteri di sicurezza del dominio incrociato. Hai aggiunto un "& callback =?" alla richiesta GET, e ora tutto funziona. – Zhami
Puoi aggiornare il tuo post originale con l'opzione di callback aggiunta? - Grazie! –
@ Zhami: Se hai risposto, dovresti pubblicare la tua soluzione come risposta qui. –