2013-10-14 15 views
9

Innanzitutto, non vi è alcun problema di area geografica.Perché jQuery considera una richiesta Ajax di 200 risposte con contenuto vuoto come fail()?

Ho trovato se il server risponde a un corpo di contenuto vuoto, jQuery considera questo come fail()?

Perché è questo?

+1

sembra un errore di analisi ... puoi aggiungere un gestore di errori come 'errore: funzione (jqXhr, stato, errore) { avviso (stato + ':' + errore + ':' + jqXhr.responseText) } ' –

+0

errori di console del browser? – karthikr

+0

Cosa 'dataType' stai usando? – WynandB

risposta

14

Se stai usando jQuery> = 1.9 una risposta JSON vuota sarà respinta, secondo il API documentation:

The JSON data is parsed in a strict manner; any malformed JSON is rejected and a parse error is thrown. As of jQuery 1.9, an empty response is also rejected; the server should return a response of null or {} instead.

12

WynandB è corretto, tuttavia v'è una risoluzione alternativa: avere il ritorno del server HTTP 204 No Content invece , che farà sì che jQuery ignori l'errore di analisi.

Problemi correlati