Return to Snippet

Revision: 63113
at April 9, 2013 09:41 by codingforever99


Initial Code
<script>
function createRequestObject(){
    var request_;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        request_ = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else{
        request_ = new XMLHttpRequest();
    }
    return request_;
}
//==============
 
var msgdiv_http = createRequestObject();
 
function msgdiv_getInfo(S1){
    t = new Date().getTime();
    URL = 'getmd5.php?c='+S1+"&t="+t;
    Obj = document.getElementById('msgdiv');
    Obj.innerHTML = '<img src="load.gif" border="0">Loading ......';
 
    msgdiv_http.open("GET", URL,true);
    msgdiv_http.onreadystatechange = msgdiv_handleInfo;
    msgdiv_http.send(null);
}
 
function msgdiv_handleInfo(){
    Obj = document.getElementById('msgdiv');
    if(msgdiv_http.readyState == 2){
        Obj.innerHTML ='<img src="load.gif" border="0">Loading ......';
    }
    if(msgdiv_http.readyState == 4){
        Obj.innerHTML = msgdiv_http.responseText;
    }
}
</script>
<input type="text" name="T1" size="20">
<input type="button" value="Encode String" id="B1" onclick ="msgdiv_getInfo(T1.value);">
<BR><BR>
<div id="msgdiv"></div>




//==================== By jQuery ================
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("#B1").click(function(){
    $("#msgdiv").load("getmd5.php?c="+T1.value);
  });
});
</script>
<input type="text" name="T1" size="20">
<input type="button" value="Encode String" id="B1">
<BR><BR>
<div id="msgdiv"></div>

Initial URL
http://function-code.blogspot.com/2013/04/using-ajax-in-javascript-and-jquery.html

Initial Description
simple code of using Ajax by JavaScript or jQuery

Initial Title
Using Ajax in JavaScript and jQuery

Initial Tags
ajax, javascript, jquery

Initial Language
JavaScript