ajax error handling works not as expected with CORS -


i've got issue cors. made setup ajax handle errors problem never triggered cross domain requests.

i know not possible catch preflights (timeouts) because fired browser, it? thought should possible catch internal server error .e.g. after. error handling works without cors (turns out 500 converted 0)

my setup never called:

jquery.ajaxsetup({         statuscode: {              500: function (data, textstatus, jqxhr) {                  if (data.status === 500) {                     window.location.hash = "#error";                 }             }         }     }); 

the request:

    jquery.ajax({         url: url,         type:'get',         timeout:1000     }).done (function (data, textstatus, jqxhr) {         updatecookie (jqxhr);         logger.log("finished loading " + log);         callback(data);      }).fail (function (data, textstatus, jqxhr) {         logger.log("failure loading " + log);      }); 

anybody hint me how around problem? greetings

update: ok debugged again , found fail called instead 0f 500 -> status 0 returned.


the request after successful preflight:

host: localhost:8080 user-agent: mozilla/5.0 (windows nt 6.1; wow64; rv:44.0) gecko/20100101 firefox/44.0 accept: */* accept-language: de,en-us;q=0.7,en;q=0.3 accept-encoding: gzip, deflate x-csrf-token: 11258a06-36ea-4a21-a935-d215fcc92714 x-requested-with: undefined origin: null connection: keep-alive 

the response server expected when trying resource deleted:

connection: close content-language: en content-type: text/html;charset=utf-8 date: mon, 08 feb 2016 20:33:12 gmt server: apache-coyote/1.1 transfer-encoding: chunked statuscode: 500 

instead of 500 in ajax setup status 0 called.

the cors specification states under cross-origin request preflight section:

the following request rules observed while making preflight request:

...

if response has http status code not in 2xx range

  • apply network error steps.

if there network error

  • in case of dns errors, tls negotiation failure, or other type of network errors, apply network error steps. not request kind of end user interaction.

therefore, preflight meets 500 response or experiences timeout (or other network failure) triggers specification's "network error steps." network error steps same error steps used whenever there general cors failure (e.g., wrong origin allowed, no cors headers present @ all, etc.):

whenever network error steps applied, terminate algorithm invoked set of steps , set cross-origin request status network error.

in browser environment, "network error" status corresponds status 0.

in order prevent happening, server must ensure preflight not fail. alternatively, change request simple (i.e., uses simple methods , headers) , therefore not require preflight.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -