Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <link rel="stylesheet" type="text/css" href="css/basic.css">
- <h1>load automatis dibawah dan reload saat tekan tombol</h1>
- <p>saat halaman ini di klik. automatis dibawah ini akan ada tulisannya. Silakan view source dan lihat bahwa dibawah tidak ada tulisan! Versi ini memasukkan perintah dalam fungsi</p>
- <p id='contoh'>kosong disini</p>
- <p> <button onclick='reload()' type='button' >Click untuk reload tulisan</button></p>
- code ajax<pre>
- $.ajax({
- url: "webservice",
- type: "GET",
- success: function(d) {
- console.log(d);
- }
- });
- </pre>
- read more : https://www.sitepoint.com/jquery-vs-raw-javascript-3-events-ajax/
- <script>
- ajaxGetShowId('001-get.php','contoh' );
- function reload(){
- ajaxGetShowId('001-get.php','contoh',true,1 );
- }
- /*
- Nama sementara
- */
- function ajaxGetShowId(url, targetId, async=true,debug=0){
- // var r = new XMLHttpRequest();
- var xhttp;
- if (window.XMLHttpRequest) {
- xhttp = new XMLHttpRequest();
- } else {
- // code for IE6, IE5
- xhttp = new ActiveXObject("Microsoft.XMLHTTP");
- }
- if(async!=true)async=false;
- xhttp.open("GET", url, async);
- xhttp.onreadystatechange = function () {
- if(debug==1){
- console.log(xhttp);
- }
- if (xhttp.readyState != 4 || xhttp.status != 200){
- return 0;
- }
- else{
- document.getElementById(targetId).innerHTML=xhttp.responseText ;
- //return xhttp.responseText;
- }
- };
- xhttp.send();
- return xhttp;
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement