Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
<script type="text/javascript">
        function CallWcfAjax() {
            var xmlHttp = new ActiveXObject("Microsoft.XmlHttp");
            var url = "http://localhost:1912/Service1.svc/ajaxEndpoint/";
            url = url + "Sum2Integers";
            var body = '{"n1":';
            body = body + document.getElementById("num1").value + ',"n2":';
            body = body + document.getElementById("num2").value + '}';
            
            //Send HTTP request
            xmlHttp.open("POST", url, true);
            xmlHttp.setRequestHeader("Content-type", "application/json");
            xmlHttp.send(body);

            //create result handler
            xmlHttp.onreadystatechange = function X() {
                if (xmlHttp.readyState == 4) {
                    var obj = xmlHttp.responseText ;

                    var newobj = eval("(function(){return " + obj + ";})()");
                    alert(newobj.d);
                    document.getElementById("num1").value = newobj.d;
                }
            }            
        }
    </script>

[edit]code block added[/edit]
Posted
Updated 11-Nov-12 21:19pm
v2

1 solution

new ActiveXObject("Microsoft.XmlHttp");


You can create activex objects only on IE. All other browsers don't know how to handle them.

There is different type of approach of ajax calls for all non IE browsers.. look it up yourself, but it looks something like this:
JavaScript
var httpRequest;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
    httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE 8 and older
    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900