What am I doing wrong with my $.get() that keeps giving me failed request??
I have no idea what I'm doing wrong, obviously haha.
Here's the example
function doAjax(){ return $.get('foo.htm'); }
function
doMoreAjax(){ return $.get('bar.htm'); }
$.when( doAjax(), doMoreAjax() ) .then(function()
{
console.log( 'I fire once BOTH ajax requests have completed!' ); })
.fail(function(){
console.log( 'I fire if one or more requests failed.' ); });
and here's what I've done. I keep getting the alert 'I fire if one or more requests failed'. What should my requests look like? It seems different from doing a normal ajax request with a url?
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script >
$(document).ready(function($) {
function doAjax(){
return $.get('https://www.sciencebase.gov/catalog/items?parentId=504108e5e4b07a90c5ec62d4&max=3&offset=0&format=json');
}
function doMoreAjax(){
return $.get('https://www.sciencebase.gov/catalog/items?parentId=504108e5e4b07a90c5ec62d4&max=3&offset=0&format=json');
}
$.when( doAjax(), doMoreAjax() )
.then(function(){
alert( 'I fire once BOTH ajax requests have completed!' );
})
.fail(function(){
alert( 'I fire if one or more requests failed.' );
});
});
</script>
</head>
<body>
</body>
</html>
I've been trying to figure out how to simply use .when() or some other method to string together multiple ajax requests and I've had zero luck. I can get one ajax request to work fine, but when it comes to using .when() I can't get anything to work?