auto_refresh div dosen't work with me - javascript

so im a beginner in php & javascript who wants to make a div contains an ads script in it to refresh every minute .
i thought i wrote everything right in my code :
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#load').load('reload.html').fadeIn("slow");
}, 60000); // refresh every 60000 milliseconds
</script>
<div id="load"></div>
and this is the reload file :
<html>
<script src="http://www.[random-website].com/getad.php?46151;80391;300x250"></script>
</html>
when the div reloads nothing happens , what the probleme ?

Its because a div with that id doesnt exist in that moment. Try this:
<script type="text/javascript">
$(document).ready(function(){
var auto_refresh = setInterval(
function ()
{
$('#load').load('reload.html').fadeIn("slow");
}, 60000); // refresh every 60000 milliseconds
});
</script>
You can also move your script block after <div id="load"></div>
You might try to update your jquery version. Ver 1.3 is obsolete.

Related

Javascript not working on page

I can't seem to get my javascript to work on my page, the same code works on another page, but not the one i'm using currently. the code is:
<script type="text/javascript">
function codeAddress() {
var $scores = $("#usersload");
setInterval(function () {
$scores.load("users.php #usersload");
}, 15000);
}
window.onload = codeAddress;
</script>
The above code should refresh a div on the page every 15 seconds, when the page loads, but does nothing, but on my other page it does what its suppose to.
if you need more code from my page let me know, but if you can help, thanks in advance!
Javascript on page:
<script>var init = [];</script>
<!-- Get jQuery from Google CDN -->
<!--[if !IE]> -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- <![endif]-->
<!--[if lte IE 9]>
<script type="text/javascript"> window.jQuery || document.write('<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">'+"<"+"/script>"); </script>
<![endif]-->
<!-- Pixel Admin's javascripts -->
<script type="text/javascript" src="assets/javascripts/bootstrap.min.js?parameter=1"></script>
<script type="text/javascript" src="assets/javascripts/pixel-admin.min.js?parameter=1"></script>
<script type="text/javascript">
init.push(function () {
// Javascript code here
});
window.PixelAdmin.start(init);
</script>
<script type="text/javascript">
function codeAddress() {
var $scores = $("#usersload");
setInterval(function () {
$scores.load("users.php #usersload");
}, 15000);
}
window.onload = codeAddress;
</script>
Could it be possible.
Have you added jQuery to the page yet, before this script block ofcourse.
The simplest way to do so..
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
Tried this on y page and this works
<script type="text/javascript">
function call(){
var $scores = $("#usersload");
$.post('user.php',{blankpost:''}, function(result){
$scores.html(result);
});
}
function codeAddress() {
setInterval( function(){
call();
}, 1000);
}
window.onload = codeAddress();
</script>
the blank post is ust to post something on the page, and just display the result
On the last line of your code, you have:
window.onload = codeAddress;
With that being said, shouldn't you still have to pass it an empty parameter such as the following?
window.onload = codeAddress();

.load() not working for me

I have a simple program that is refreshing an page every 100 milliseconds. But when i am trying to run it i am simply getting an blank page.Here is my html
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#load_tweets').load('demo.php').fadeIn("slow");
}, 10000); // refresh every 10000 milliseconds
<body>
<div id="load_tweets"> </div>
</body>
</script>
Please help me to solve this problem as i am beginner to jquery.Thanks in advance
the problem is closing script tag
try like this
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('#load_tweets').load('record_count.php').fadeIn("slow");
}, 10000); // refresh every 10000 milliseconds
</script>
</head>
<body>
<div id="load_tweets"></div>
</body>
</html>
Use setTimeOut() instead.
setTimeout("yourfunction()", 1000); // call yourfunction() after 1 second
function yourfunction(){
//do what you want
}
Also correct your HTML!

$(document).ready(function () { ... won't fire

I have the following code at the end of one of my Views:
#section Scripts {
<script type="text/JavaScript">
$(document).ready(function () {
alert("!!!");
});
</script>
}
What ever I do, I can't get it to fire. I have checked and further up in the code JQuery is included. Using the suggestion here I changed my code to the following to confirm that jquery was correctly loaded. This gives the 'Yeah!' alert when loading the page.
#section Scripts {
<script type="text/JavaScript">
window.onload = function () {
if (window.jQuery) {
// jQuery is loaded
alert("Yeah!");
} else {
// jQuery is not loaded
alert("Doesn't Work");
}
}
</script>
}
The end of the source in my page looks like:
<script src="/Scripts/jquery-1.9.1.js"></script>
<script src="/Scripts/jquery-ui-1.8.24.js"></script>
<script src="/Scripts/bootstrap.js"></script>
<script src="/Scripts/breakpoints.js"></script>
<script src="/Plugins/jquery-unveil/jquery.unveil.js"></script>
<script src="/Plugins/jquery-fademenu/jquery.fademenu.js"></script>
<script src="/Plugins/jquery-block-ui/jqueryblockui.js"></script>
<script src="/Plugins/jquery-slimscroll/jquery.slimscroll.js"></script>
<script src="/Plugins/bootstrap-select2/select2.js"></script>
<script src="/Plugins/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
<script src="/Plugins/dropzone/dropzone.js"></script>
<script src="/Scripts/core.js"></script>
<script type="text/JavaScript">
$(document).ready(function () {
alert("!!!");
});
</script>
<!-- Visual Studio Browser Link -->
<script type="application/json" id="__browserLink_initializationData">
{"appName":"Chrome","requestId":"6301d560dc274f4ea5ec24b8e0c2a19f"}
</script>
<script type="text/javascript" src="http://localhost:50280/1cd42285f06243669b1fd5837f1f05c3/browserLink" async="async"></script>
<!-- End Browser Link -->
</body>
</html>
I can't work out where I am going wrong...
if this coode works properly
window.onload = function () {
if (window.jQuery) {
// jQuery is loaded
alert("Yeah!");
} else {
// jQuery is not loaded
alert("Doesn't Work");
}
}
and this code doesn't :
$(document).ready(function () {
alert("!!!");
});
your likely problem is that there is a conflict with the dollar sign $
I would type out jQuery instead of using the dollar sign , or of course you can do something like this:
var j = jQuery.noConflict();
then you can do use the j where you used to use $
OR... there is simply just an error in the console that you still have not responded about , if that is the case I will update answer
EDIT::
The reasons that you code was not executing was because javascript is weird in the sense that if there is an error anywhere in the block of javascript code then nothing below it will be executed. That is why I asked if there were any console error's. Checking the console is the first step to solving any javascript error.
remove #section Scripts block put script block only and try... if not then remove all js use only jquery and try it will definatly. now add one by one script and find one which is conflicting. .

Onload function interferes with page refresh

I have inherited an app that has this code at the top of every page, after the head tag:
script src="sorttable.js"></script>
<title>Positions</title>
<noscript>
<meta http-equiv="refresh" content="30">
</noscript>
<script type="text/javascript">
<!--
var sURL = unescape(window.location.pathname);
function doLoad()
{ setTimeout( "refresh()", 30*1000 ); }
function refresh()
{ window.location.href = sURL; }
//-->
</script>
<script type="text/javascript">
<!--
function refresh()
{ window.location.replace( sURL ); }
//-->
</script>
<script type="text/javascript">
<!--
function refresh()
{ window.location.reload( true ); }
//-->
</script>
This works, and the page refreshes itself every 30 seconds. (As an aside, I don't understand this code - why there's 3 functions with the same name - and why if I remove any of those functions it either doesn't refresh at all, or when it refreshes it get's an 'untrusted connection' error. But that is not my question.)
In some cases I have to run some code when the page loads:
<script type="text/javascript">
window.onload = function() { sorttable.innerSortFunction.apply(document.getElementById("FVShort-4"), []); }
</script>
My problem is that in the cases when I do have that onload function, the pages no longer refreshes. How can I have both the onload function and still have the automatic refresh work?

Remove/Disable internal javascript

Is it possible to remove/disable internal JavaScript on a page after 'X' minutes so that it does not work at all after 'X' minutes of time?
Try like below,
<script type="text/javascript" id="hideAfter">
// your code here...
// it will removes the script tag after 10 sec...
setTimeout(function () {
var ele = document.getElementById("hideAfter");
ele.parentNode.removeChild(ele);
}, 10000);
</script>

Categories

Resources