Friday, February 13, 2015

HTTP Request with Javascript

<script type="text/javascript">

var oReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");

function handler()
    if (oReq.readyState == 4 /* complete */) {
        if (oReq.status == 200) {
            document.getElementById("myDiv").innerText = oReq.responseText;

function SendRequest()
    var vURL = "http://IdolApp:12345/data/data.xml";

    if (oReq != null) {"GET", vURL, true);
        oReq.onreadystatechange = handler;
    else {
        window.console.log("AJAX (XMLHTTP) not supported.");

<input type="button" id="btnSubmit" value="Go" onclick="SendRequest()"/>
<div id="myDiv" >:o)</div>

Initialize the oReq with following to make it IE and Chrome compatible:
var oReq;

if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
 oReq=new XMLHttpRequest();
{// code for IE6, IE5
 oReq=new ActiveXObject("Microsoft.XMLHTTP");

Knowledge Chat Bot (No Code)

Recently my customers was looking for a solution where on-field guys can search for answers related to their tasks and it was a perfect scen...