Is there a way to delay a CORS request?

时间:2016-07-11 20:17:05

标签: jquery cors delay

I am using CORS to pull back some content from a webpage. Obviously this webpage is on a different server than the one I'm using (thus the need for CORS). Here's my blippit of code.

<div id="target-div2"></div>
<script>$('#target-div2').load('http://dcll.ent.sirsi.net/client/en_US/test/search/results?qu=NEW_DVDS #results_wrapper');</script>

Basically this fetches the content within the div with the ID results_wrapper and puts it in my target-div2 on my page. The problem I'm having is that the code fetches the content before the off-server page is 100% loaded. Well sort of...the off-server page loads and then appears to also have to go off-server to fetch some images. So basically the page initially loads with some temporary placeholder images and then a script runs and it goes to fetch the missing images. Does that make sense?

What I'm wondering is if there is a way to delay the gathering of the content for a second before returning it back to my page.

1 个答案:

答案 0 :(得分:0)

Could you try to set up a callback like this ?

<div id="target-div2"></div>
<script>
var callback = function(){
    $('#target-div2').load('http://dcll.ent.sirsi.net/client/en_US/test/search/results?qu=NEW_DVDS #results_wrapper');
}
$( document ).ready(callback);
</script>