Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ajaxGetShowId(url, targetId, async=true,debug=0){
- var xhttp=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;
- }
- };
- xhttp.send();
- /*bila TIDAK menggunakan async maka bisa mengembalikan hasil*/
- response={detail:xhttp, text:xhttp.responseText, state:xhttp.readyState, status:xhttp.status, url:xhttp.responseURL, type:xhttp.responseType}
- return response;
- }
- function ajaxGetJson(url,async=false, debug=0){
- var xhttp=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;
- }
- };
- xhttp.send();
- response=xhttp.responseText;
- json=JSON.parse(response);
- return json;
- }
- function xmlHttp(){
- if (window.XMLHttpRequest) {
- xhttp = new XMLHttpRequest();
- } else {
- // code for IE6, IE5
- xhttp = new ActiveXObject("Microsoft.XMLHTTP");
- //new ActiveXObject("MSXML2.XMLHTTP.3.0")
- }
- return xhttp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement