Friday 15 July 2011

javascript - How to handle CORS error code? -



javascript - How to handle CORS error code? -

edit: realized duplicate of recommended solution ajax, cors, chrome & http error codes (401,403,404,500), , tried thought propose @ end. can't tell if succeeded (dud user?), , no 1 else has posted solution or comment, think it's worth fishing new answers.

problem:

i send properly-executed (edit: improperly-executed. end of story...) cors request. the server receives request , attempts process it. the server returns error response, illustration 422 unprocessable entity, along json info errors. thought app receive error info , handle appropriately in ui. the browser blocks error handler getting response content, or getting status code.

showing browser received 401 status code treated cors security error:

the response object, showing code cannot access response info (data: "", status: 0):

how have other people handled limitation? best guess right hijack http "success" code (2xx) error code, , include error info in response. prevents me using ajax error handlers in normal way, i'm handling global ajax filter anyway, filter capture deviant success code , trigger error handlers instead.

the console message indicates server isn't sending required access-control-allow-origin header when sends 401 response code.

you won't able utilize cors error handler inject content dom unless prepare that.

the server sending header correctly on responses 200 response code. needs other response codes, though, if wish utilize info response codes.

fix on server end before making design compromises on client side. may solve problem straight away.

javascript ajax http cors

No comments:

Post a Comment