일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- JSON
- phonegap
- GPS
- jsr 296
- PHP
- MFC
- Android
- Ajax
- JDOM
- tomcat
- jQuery
- WebLogic
- appspresso
- PLSQL
- 전자정부프레임워크
- 가우스
- MySQL
- 선택적조인
- iBATIS
- rowspan
- node.js
- swingx
- Struts
- ibsheet
- dock
- Spring
- oracle
- Eclipse
- Google Map
- sencha touch
- Today
- Total
Where The Streets Have No Name
jquery ajax error handling 본문
jQuery is the most awesome javascript library that made easy for asynchronous ajax calls.it has global ajaxfunction and some pre defined ajax functions like $.get, $.post, load .etc. but we don’t find any error messagesby default with this library. we can see the errors with firefox’s addon firebug or with IE developer toolbar.So we manage most common ajax errors in our application with global ajaxSetup function which come with jQueryby default. We can set many options,to see available ajaxsetup options please check here.
most ajax errors we get errors are server response errors and some JSON parse errors. To know more about the HTTP errors details please check here. To test this error handling just copy and paste it to your head section of HTML document.
Javascript Code for setting global error handling.
In the above example we handle following common error and show response text for other rare errors.
- 0-xhr status ,is it initialized or not that means user is offline.
- 404-page not found
- 500-Internel Server error.
- request timeout – jQuery custom error.
- parseerror-jQuery custom error when parsing JSON data.
- we just throw other errors with response error
Example1
In above example,jQuery automatically raises all available errors,except parse error. because we didn’t give any return type format.
Example2
In above example,jQuery automatically raises all available errors,because we added return type format at end. $.getJSON automatically adds the return type of parameter to “JSON”
Example3
In the above example 3 ,we gave xml type return parameter, here also jQuery automatically raises all errors even parse error also.