Friday, February 20, 2015

Getting data from a webservice

var xmlhttp = new XMLHttpRequest();
        if (window.XMLHttpRequest)
            xmlhttp = new XMLHttpRequest();
        else
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        xmlhttp.open("GET", SERVICEURL, false);
        xmlhttp.send();
        var xmlDoc = xmlhttp.responseXML;
        if (xmlDoc != null) {
                var email = xmlDoc.getElementsByTagName("email");//Here email is the field returned from the service
                if (email != null && email != undefined && email.length != 0) {
                    document.getElementById('<%= lblEmail.ClientID %>').innerHTML = email[0].childNodes[0].nodeValue;
                    document.getElementById('lnkEmail').setAttribute('href', "mailto:" + email[0].childNodes[0].nodeValue);
                }
            }
        }

No comments:

Post a Comment