Total members 11894 |It is currently Sun Nov 24, 2024 3:37 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





In AJAX you use XMLHttpRequest object and waits for readyState, in case of error state is 4:
Code:
   if(request)
   {
   //The autocalled funtion when the status changed
request.onreadystatechange = function() {

//Status cases of the readState varrible
  if(request.readyState==0)
document.getElementById('status').innerHTML='Uninitialized';
else  if(request.readyState==1)
document.getElementById('status').innerHTML='Loading...';
else  if(request.readyState==2)
document.getElementById('status').innerHTML='Loaded';
else  if(request.readyState==3)
document.getElementById('status').innerHTML='Interactive';
else  if(request.readyState==4)
{
document.getElementById('status').innerHTML='Completed';
var xml_response = request.responseXML;
xml_response.loadXML(request.responseText);
    var myname=xml_response.getElementsByTagName('name');
    document.getElementById('Txtdata').value=myname[0].childNodes[0].nodeValue;
}


in case of using DOJO toolkit error code is 500

Code:

dojo
.xhrPost( {
    url: 'service URL',
    content: {},
    handleAs: 'text',
    load: function(response, ioArgs) {
        // Do something
    },
    error: function(response, ioArgs) {
        alert("Failed while doing the operation: " + ioArgs.xhr.response);
    }
});
 





If you are connecting to a web-server which runs a Servelt and wants to return error for ajax code at client side you can set exception as follows :
Code:

public class siteServelt extends HttpServlet 
{

    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        
        try 
{
             // Your code site here.
        } catch (Exception exception) {
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                    response.getWriter().write(exception.getMessage());
                    response.flushBuffer();            
        
} finally {
             
        
}
    }
    
}
 




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Error handling in AJAX
 AJAX SYNTAX ERROR IE     -  
 Solution to Error status zero when using Ajax with JQuery     -  
 What is AJAX, How to start AJAX?     -  
 Exception handling     -  
 What is Event Handling?     -  
 Session handling using Struts     -  
 Exception Handling in a project     -  
 Material Handling Equipment     -  
 try-with-resource automatic handling     -  
 Event Handling Notes     -  



Topic Tags

AJAX
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com