Reputation: 1213
When I use a load() in load() function to load different elements from another page in one I have two request.
How can I make into one? Like this idea:
$mainContent.load(newHash + " .first"," .second", function() { });
Cause the problem I ran in is that a page that I loaded with a contact form sends twice cause I "thinks" it got loaded twice.
Heres the full code fragment:
if (newHash) {
$claim.find("#claim").find("p").fadeTo(200,0);
$mainContent.find(".maincontent").fadeTo(200,0, function() {
$mainContent.fadeTo(0,0).load(newHash + " .maincontent", function() {
$claim.find("#claim").find("p").fadeTo(0,0, function() {
$claim.load(newHash + " #claim", function() {
$("#claim").fadeTo(0,0).fadeTo(200,1);
$mainContent.fadeTo(200,1);
});
});
});
});
};
So how am I able to load multiple, different items with only one .load() request?
Is that possible?
Thank you.
Upvotes: 5
Views: 7162
Reputation: 11
I realize it's a bit late for this answer, but I found a solution to this problem. No need to make several requests to the server.
$('.first').load(url+' .first > *', function(response){
let res = response
$('.second').html($(res).find('.second').html())
})
Upvotes: 0
Reputation: 1213
This works:
$mainContent.load(newHash + " .first, .second", function() { });
The answer is right here:
Upvotes: 2
Reputation: 13233
It would have to be an individual .load, then the function() can be a seperate function that is ran once all .loads are done. You have to focus on the function() part, rather than how you're attacking it. Or another option would be to do your multi-loading in the actual file, but i'm sure you've thought of that one. ;)
Here is one way you would do it, you can manipulate the i variable and while function accordingly:
<script type="text/javascript">
var i=0;
while (i<=5)
{
document.write("The number is " + i);
document.write("<br />");
i++;
}
</script>
Upvotes: 0