July 2011
Intermediate to advanced
276 pages
5h 11m
English
If our visitor's Internet connection fails, our script should tell them the Ajax will not work either.
Create a test script that makes an Ajax call. Ensure the call will fail by using a fake domain that will not resolve.
<form action="" method="get">
<input type="button" id="mybutton" value="Ajax!"/>
</form>
<script type="text/javascript">
var myJax = new Request({
url: 'http://incorrectdomain.com/nofileexists',
onFailure: function() {
alert('error connecting, Ajax call has failed :(');
},
onSuccess: function(response) {
alert('Success! Here is the response: '+response);
}
});
$('mybutton').addEvent('click', function ajax_it() {
myJax.send();
});
</script>
Using a fake URL will ...