In wordpress I have a page set up to pull in a random post, using jQuery I’m looking to pull in sections of this (random) page to various sections on the current (home) page at the moment the code is as below:
$('#wrongQuote').load('random/index.php #wrongSaying' + '?noCache=' + Math.floor(Math.random()*10001));
$('#sayingBy').load('random/index.php #author' + '?noCache=' + Math.floor(Math.random()*10001));
$('#actualQuote').load('random/index.php #actualSaying' + '?noCache=' + Math.floor(Math.random()*10001));
The trouble is this is pulling in a random #wrongSaying, #author and #actualSaying… what I need is to get random, but matching #wrongSaying / #author / #actualSaying
So I guess what I need is get this page ‘random/index.php #wrongSaying’ then take div#x and insert into div#a, div#f into div#e and so on…
Any ideas / help would be much appreciated!
Andy
I wouldn’t use
.load()with 3 requests here, I’d do the loading yourself and make one request to the server using$.get(), like this:The fragment loading you get with
.load()is nothing you can’t do yourself…and when you’re repeating the same request it’s something you shouldn’t do yourself…be efficient and make one request, with more readable code IMO.