以下代码在Firefox Mozilla浏览器中不起作用 [英] Following code is not working in Firefox Mozilla browser

查看:80
本文介绍了以下代码在Firefox Mozilla浏览器中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<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]代码块已添加[/edit]

推荐答案

new ActiveXObject("Microsoft.XmlHttp");


您只能在IE上创建activex对象.所有其他浏览器都不知道如何处理.

对于所有非IE浏览器,都有不同类型的ajax调用方法..自行查找,但看起来像这样:
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");
}


这篇关于以下代码在Firefox Mozilla浏览器中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆