Click here to Skip to main content
14,384,019 members
Rate this:
Please Sign up or sign in to vote.
See more:
<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 22:19pm
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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:
var httpRequest;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
    httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE 8 and older
    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100