2011-09-20 59 views
0

如何在JQuery错误处理函数中添加$ .get? 我的请求看起来像

$.get('www.test.com', temp_parameters, function(data) { 
      alert('data='+data['result']); 
     },"json"); 

但如果发生错误,则没有功能。在哪里添加该功能?

+3

使用'$ .ajax':http://api.jquery.com/jQuery.ajax/ –

回答

1

如果您使用jQuery 1.5或更高版本,您可以添加错误方法。

段从 - http://api.jquery.com/jQuery.get/

var jqxhr = $.get("example.php", function() { 
    alert("success"); 
}) 
.success(function() { alert("second success"); }) 
.error(function() { alert("error"); }) 
.complete(function() { alert("complete"); }); 

你可以阅读更多关于它。除此之外,Flex提到$ .ajax是最好的选择。