I'm using the following code to get some data from an external website.
<script type="text/javascript">
xui.ready(function() {
var url = 'http://www.domain.com/getData.aspx';
x$().xhr(url,function(){
alert(this.responseText);
});
}
);
</script>
UPDATED:
I updated my code to the following but even if I get a 404, the callback function still fired and not 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 above code work just fine but this morning, the external website was down and this was causing the page to fail. Based on the documentation, it looks like the callback function is called only when the xhr called received status 200. What is the best way to handle error 500 or 404?
Have you read the documentation ?
Take a look at the {options} you can pass as an argument: