JQuery Ajax 捕获异常

function deleterepair(repairid) {
	var id = $('#repair_id').val();
	$.ajax( {
		url : 'RepairAction!delRepair.action?repairid=' + id,
		type : 'post',
		dataType : 'json',
		success : function(data, textStatus, jqXHR) {
			if(data=='...'){         //对服务器端返回的数据进行判断;前提是在action中设置好返回参数;
                            alert('......');//处理方法;
                        }else{    

                            alert('......');//处理方法;

                        }
				
		}

	});

}


另一种方法:

function deleterepair(repairid) {
	var id = $('#repair_id').val();
	$.ajax( {
		url : 'RepairAction!delRepair.action?repairid=' + id,
		type : 'post',
		dataType : 'json',
		success : function(data, textStatus, jqXHR) {

                            alert('......');//处理方法;
		
		}
                error:function(XmlHttpRequest,textStatus, errorThrown)
                {
                     alert('删除失败'+XmlHttpRequest.responseText);
                }
      });   
 }

版权声明:本文为博主原创文章,未经博主允许不得转载。

原文地址:https://www.cnblogs.com/dqsweet/p/4927810.html