Reputation: 35
I've been struggling with this for far too many hours and hoping you guys can point out if I'm doing something wrong.
I have a wordpress page that loaded videos from JSON feed using php, but it loads too slow for my liking and I wanted to run the php scripts after the page loaded using jquery.
I tested it several times and it works as expected when I test on a blank page, but when I'm trying to load it right into a wordpress template, it's oddly redirecting.
So, here is the basic jquery I'm using to load:
<script type="text/javascript">
$(document).ready( function() {
setTimeout( function() {
$('#main-video-list').html('').load('../test.php');
}, 4000);
});
</script>
The timeout is just to give it some wait time so I can easily see it run after some other things load. The issue I can't seem to find a way around is that everytime this function triggers, it actually redirects the entire window to the url being loaded, in this case test.php.
It doesn't seem to be related to the script being sent in, because if I change test.php to include just a simple paragraph of text, it acts the same way.
(Update: it preserves the url of the previous page, but all elements are gone. It results in a blank page with only the stuff loaded from test.php)
Has anyone experienced this? I cannot find anything online where people are having the same issue, but I just cannot put my finger on what is causing it either.
Any help or insight would be greatly appreciated!
(edited to update code based on comment from @nnnnn)
Upvotes: 1
Views: 2243
Reputation: 51
I had this same problem. Turned out that the HTML returned from the .load() call had a <script> tag inside it, that was doing a document.write(...). I removed this <script> and the problem went away. Maybe this is your issue as well.
Upvotes: 1