Jump to content

Need To Catch Error in Success Function in jQuery


logicslab

Recommended Posts

Hi Friends,

  I am come with a new query in jQuery. I have a listing form in which the details showed , the View more Details is implemented using Ajax.

  When Click "+" sign there is a loading image show First then the Result show there ... It's all working Fine , But I need a way to show Error

I mean some time Server Response is success with Empty String on that time I need to catch same .... I explain code Below:

 if(proceed) {
      $.ajax({
	  	type: "POST",
	  	data: "key="+id,
	  	dataType: 'json',
	  	async: true,
	  	url: "<?php echo site_url(); ?>/server/view_serverdet/",
	  	beforeSend: function() {
        	$('#view_load'+id).show();
        	$('#view_load'+id).addClass(class);
  		},
        complete: function(){
                      	
        		$('#view_load'+id).hide();
        	}
        },
	  	success: function (server_msg) {
	  		if (null == server_msg) {
	  			var warning = "<font color=\"red\">Unable to load server details</font>";
                	$('#view_load'+id).html(warning);
			} else {

                       // Working Fine!
                               }

 

But that error Just Show and Hide ... How I can show that Error there, If you have any idea , pls help me ASAP...

 

Thankfully

Anes P.A  :)

As stated before your description is quite hard to understand.

However I do see something in your code that in your code that makes me think that your looking for the error handler of the ajax object.

 

In your code I see this :

var warning = "<font color=\"red\">Unable to load server details</font>";

 

To see if an error occurs try something like:

$.ajax({
    success: function() {
        // your normal action when the server call is running as expected
    },
    error: function() {
        // your code when a error occurs on the server such as a timeout
    }
});

 

if this was not what you were looking for can you try again describing your exact problem?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.