Dj_Stay Posted June 5, 2011 Report Share Posted June 5, 2011 (edited) Sveiki, es taisu webu un man gribās uzstaisīt, monitõram un statistkai to, lai nevaig taisīt refresh, lai JS automātiski refresho.. Varbūt nemāku izskaidrot, bet ir dažos webos tā. Atradu kaut ko šādu. <script> $(document).ready(function() { $("#responsecontainer").load("response.php"); var refreshId = setInterval(function() { $("#responsecontainer").load('response.php?randval='+ Math.random()); }, 9000); $.ajaxSetup({ cache: false }); }); </script> Edited June 5, 2011 by Dj_Stay Link to comment Share on other sites More sharing options...
Dj_Stay Posted June 5, 2011 Author Report Share Posted June 5, 2011 Skaidrs.. Es tāā dzīļi, dziļi pameklēju un atradu. Ja kādam vaig ņemat. <script type="text/javascript"> function ajaxFunction(){ var ajaxRequest; try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ //browsers all not support, rare case alert("Your browser broke!"); return false; } } } return ajaxRequest; } function showData() { htmlRequest = ajaxFunction(); if (htmlRequest==null){ // If it cannot create a new Xmlhttp object. alert ("Browser does not support HTTP Request"); return; } htmlRequest.onreadystatechange = function(){ if(htmlRequest.readyState == 4){ document.getElementById("shoutarea").innerHTML = htmlRequest.responseText; } } htmlRequest.open("GET", "mon/pub.php", "inc/jaunforum.php", true); htmlRequest.send(null); } showData(); setInterval("showData()",10000); function saveData(){ htmlRequest = ajaxFunction(); if (htmlRequest==null){ // If it cannot create a new Xmlhttp object. alert ("Browser does not support HTTP Request"); return; } if(document.shoutbox.shouter_comment.value == "" || document.shoutbox.shouter_comment.value == "NULL"){ alert('Monis zdohnul?! '); return; } htmlRequest.open('POST', 'mon/pub.php', 'inc/jaunforum.php'); htmlRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); htmlRequest.send('message='+document.shoutbox.shouter_comment.value); document.shoutbox.shouter_comment.value = ''; // Updates the shout box’s text area to NULL. document.shoutbox.shouter_comment.focus(); // Focuses the text area. } </script> Lai palaistu raksti div <div id="shoutarea"> To, ko vaig refresh </div> Link to comment Share on other sites More sharing options...
blindmind Posted June 5, 2011 Report Share Posted June 5, 2011 Nafig AJAX, pirmais kods tikpat labi dereja. Link to comment Share on other sites More sharing options...
Dj_Stay Posted June 5, 2011 Author Report Share Posted June 5, 2011 Nafig AJAX, pirmais kods tikpat labi dereja. Nūū man pirmais neiet Link to comment Share on other sites More sharing options...
blindmind Posted June 5, 2011 Report Share Posted June 5, 2011 jQuery ieklaavi head tagos? Link to comment Share on other sites More sharing options...
Dj_Stay Posted June 5, 2011 Author Report Share Posted June 5, 2011 Itkā <script type="text/javascript" language="javascript" src="inc/js/jquery-1.3.2.min.js"></script> Kr4 ir tāā, ka man refresh ir monim, bet Jaunākais forumā nav. Izmantoju šito script. <script type="text/javascript"> function Ajax(){ var xmlHttp; try{ xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari } catch (e){ try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer } catch (e){ try{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ alert("No AJAX!?"); return false; } } } xmlHttp.onreadystatechange=function(){ if(xmlHttp.readyState==4){ document.getElementById('shoutarea').innerHTML=xmlHttp.responseText; setTimeout('Ajax()',10000); } } xmlHttp.open("GET","mon/pub.php","inc/jaunforum.php",true); xmlHttp.send(null); } window.onload=function(){ setTimeout('Ajax()',10000); } </script> Link to comment Share on other sites More sharing options...
Turismox Posted June 5, 2011 Report Share Posted June 5, 2011 no kada saita tu tos kodus dabuji? google ari pastav.. <script type="text/javascript" language="javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script> <script> $(document).ready(function(){ /* pirmais */ $("#huina").load('/kkas.html'); /* otrs */ $("#huina2").load('/kkas2.html'); }); /* pirmais */ var refreshId = setInterval(function() { $('#huina').load('/kkas.html'); }, 5000); /* otrs */ var refreshId = setInterval(function() { $('#huina2').load('/kkas2.html'); }, 5000); </script> <div id="huina"> <div style="display:block;margin:0 auto" />ieladee1</div> </div> <div id="huina2"> <div style="display:block;margin:0 auto" />ieladee2</div> </div> Link to comment Share on other sites More sharing options...
Dj_Stay Posted June 5, 2011 Author Report Share Posted June 5, 2011 no kada saita tu tos kodus dabuji? google ari pastav.. <script type="text/javascript" language="javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script> <script> $(document).ready(function(){ /* pirmais */ $("#huina").load('/kkas.html'); /* otrs */ $("#huina2").load('/kkas2.html'); }); /* pirmais */ var refreshId = setInterval(function() { $('#huina').load('/kkas.html'); }, 5000); /* otrs */ var refreshId = setInterval(function() { $('#huina2').load('/kkas2.html'); }, 5000); </script> <div id="huina"> <div style="display:block;margin:0 auto" />ieladee1</div> </div> <div id="huina2"> <div style="display:block;margin:0 auto" />ieladee2</div> </div> Paldies, strādā. Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now