user ajax to get data without "onClick function" in javaScript -
i've been searching example of getting data using ajax without onclick function of example found within onclick funtion.
here html data using onclick funtion
<!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <title>new document</title> <script type = 'text/javascript' src='js/jquery-2.2.0.js'></script> <script type ='text/javascript' src='js/testscript.js'></script> <?php include_once("database_conn_getoffers.php"); ?> </head> <body> content goes here <aside id="offer" onclick ="loaddoc('getdata.php',myfunction)"> click here </aside> </body>
here script
function loaddoc(url, cfunction) { var xhttp; xhttp=new xmlhttprequest(); xhttp.onreadystatechange = function() { if (this.readystate == 4 && this.status == 200) { cfunction(this); } }; xhttp.open("get", url, true); xhttp.send(); } function myfunction(xhttp) { document.getelementbyid("offer").innerhtml = xhttp.responsetext; }
now, wanted data without onclick function.
want data show once open html.
can provide me link or gv me example ??
body onload doesnt required. can directly use window onload function in js
js
window.onload = function() { loaddoc('getdata.php',myfunction) };
Comments
Post a Comment