Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > it.comp.lang.javascript > #7938 > unrolled thread
| Started by | Meldro <Meldro@nospam.no> |
|---|---|
| First post | 2015-11-25 16:15 +0100 |
| Last post | 2015-11-26 05:13 -0800 |
| Articles | 3 — 3 participants |
Back to article view | Back to it.comp.lang.javascript
intercettare "error" su chiamata ajax. Meldro <Meldro@nospam.no> - 2015-11-25 16:15 +0100
Re: intercettare "error" su chiamata ajax. Alessandro Pellizzari <shuriken@amiran.it> - 2015-11-25 19:53 +0000
Re: intercettare "error" su chiamata ajax. 4ndre4 <a.laforgia@gmail.com> - 2015-11-26 05:13 -0800
| From | Meldro <Meldro@nospam.no> |
|---|---|
| Date | 2015-11-25 16:15 +0100 |
| Subject | intercettare "error" su chiamata ajax. |
| Message-ID | <n34jbl$tmr$1@speranza.aioe.org> |
Salve a tutti,
ho del codice JS che esegue una chiamata ajax in questi termini:
$.ajax({
url: "calcolo.php",
type: "POST",
data: dataString,
dataType: "json",
success: function(output) {
elabora(output);
},
error: function() {
alert("Chiamata fallita, si prega di riprovare...");
}
});
La chiamata sistematicamente mi va in error e restituisce l'alert specifico.
Vorrei capire PERCHE' mi va in error e non in success, visto che quello
che esce dal file calcolo.php è comunque in JSON formalmente valido.
Non dovrebbe uscire in success?
Come posso capire cosa non va?
Grazie in anticipo.
[toc] | [next] | [standalone]
| From | Alessandro Pellizzari <shuriken@amiran.it> |
|---|---|
| Date | 2015-11-25 19:53 +0000 |
| Message-ID | <dbmhuhFl3haU1@mid.individual.net> |
| In reply to | #7938 |
Il Wed, 25 Nov 2015 16:15:57 +0100, Meldro ha scritto:
> ho del codice JS che esegue una chiamata ajax in questi termini:
>
> $.ajax({
> url: "calcolo.php",
> ...
> La chiamata sistematicamente mi va in error e restituisce l'alert
> specifico.
Le chiamate AJAX di jQuery vanno in error quando il server non restituisce
un codice 2xx (solitamente 200, ma dipende da come hai strutturato il
programma).
> Vorrei capire PERCHE' mi va in error e non in success, visto che quello
> che esce dal file calcolo.php è comunque in JSON formalmente valido.
Sei sicuro che sia formalmente valido? C'è l'header Content-type corretto?
La risposta torna il codice corretto?
> Come posso capire cosa non va?
Il modo più veloce è usare Firefox con Firebug e vedere nella console il
tracciamento della chiamata: quali header partono, quali tornano, come
viene vista la risposta.
Bye.
[toc] | [prev] | [next] | [standalone]
| From | 4ndre4 <a.laforgia@gmail.com> |
|---|---|
| Date | 2015-11-26 05:13 -0800 |
| Message-ID | <06e3a8e9-2473-447f-b3ac-a69f47f71090@googlegroups.com> |
| In reply to | #7938 |
On Wednesday, 25 November 2015 15:16:08 UTC, Meldro wrote: [...] > Come posso capire cosa non va? Facendo debug, ovviamente. Passo passo, analizzando cio` che viene passato sulla rete come richiesta/risposta. Inoltre: "error Type: Function( jqXHR jqXHR, String textStatus, String errorThrown ) A function to be called if the request fails. The function receives three arguments: The jqXHR (in jQuery 1.4.x, XMLHttpRequest) object, a string describing the type of error that occurred and an optional exception object, if one occurred. Possible values for the second argument (besides null) are "timeout", "error", "abort", and "parsererror". When an HTTP error occurs, errorThrown receives the textual portion of the HTTP status, such as "Not Found" or "Internal Server Error." As of jQuery 1.5, the error setting can accept an array of functions. Each function will be called in turn. Note: This handler is not called for cross-domain script and cross-domain JSONP requests. This is an Ajax Event." http://api.jquery.com/jquery.ajax/ Aggiungi i parametri alla tua funzione di errore e vedi qual e` lo status code che ti restituisce il server e che errore esattamente viene sollevato.
[toc] | [prev] | [standalone]
Back to top | Article view | it.comp.lang.javascript
csiph-web