Last active
June 15, 2016 00:59
-
-
Save ridinghoodmedia/d96f8128b55d9c29b7d092377d2af5b6 to your computer and use it in GitHub Desktop.
Useful ajax snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Since the settings object is tied to that ajax call, you can simply add in the indexer | |
// as a custom setting, which you can then access using this in the success callback: | |
// http://stackoverflow.com/questions/18413969/pass-variable-to-function-in-jquery-ajax-success-callback | |
//preloader for images on gallery pages | |
window.onload = function() { | |
var urls = ["./img/party/","./img/wedding/","./img/wedding/tree/"]; | |
setTimeout(function() { | |
for ( var i = 0; i < urls.length; i++ ) { | |
$.ajax({ | |
url: urls[i], | |
indexValue: i, | |
success: function(data) { | |
image_link(data , this.indexValue); | |
function image_link(data, i) { | |
$(data).find("a:contains(.jpg)").each(function(){ | |
console.log(i); | |
new Image().src = urls[i] + $(this).attr("href"); | |
}); | |
} | |
} | |
}); | |
}; | |
}, 1000); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment