Recently, I've been utilizing the code below to extract data from an external source.
<script type="text/javascript">
xui.ready(function() {
var url = 'http://www.domain.com/getData.aspx';
x$().xhr(url,function(){
alert(this.responseText);
});
}
);
</script>
UPDATE:
I made adjustments to my code as seen below. However, even in cases where I encounter a 404 error, the callback function is still triggered instead of the error function.
<script type="text/javascript">
xui.ready(function() {
var url = 'http://localhost:49617/SalesForceWebservice/Test/Default4.aspx';
x$().xhr(url,{
method: 'get',
async: true,
error: function(){
alert('error');
},
callback: function(){
alert('success');
}
});
}
);
</script>
The mentioned code functions properly but earlier today, the external website encountered technical difficulties which resulted in page failures. According to the provided documentation, it seems that the callback function is only executed when the xhr call obtains a status of 200. How should I handle errors such as 500 or 404 in this scenario?