Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Firefox从JavaScript调用REST API不起作用_Javascript_Api_Firefox_Rest - Fatal编程技术网

使用Firefox从JavaScript调用REST API不起作用

使用Firefox从JavaScript调用REST API不起作用,javascript,api,firefox,rest,Javascript,Api,Firefox,Rest,我使用下面的代码使用JavaScript调用RESTAPI。这段代码在IE上运行良好,但在Firefox 9.0.1的send方法上挂起。我相信IE没有兑现之前的回应 <script language="javascript" type="text/javascript"> function processRequest() { var signedURI = "http://api.saaspose.com/v1.0/storage/disc?appSI

我使用下面的代码使用JavaScript调用RESTAPI。这段代码在IE上运行良好,但在Firefox 9.0.1的send方法上挂起。我相信IE没有兑现之前的回应

<script language="javascript" type="text/javascript">

    function processRequest() {
         var signedURI = "http://api.saaspose.com/v1.0/storage/disc?appSID=myappSID&signature=mySignature";

        var xmlhttp = null;

        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
            if (typeof xmlhttp.overrideMimeType != 'undefined') {
                xmlhttp.overrideMimeType('text/xml');
            }
        } else if (window.ActiveXObject) {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } else {
            alert('Not supported!');
        }

        xmlhttp.open('GET', signedURI, true);

        xmlhttp.onreadystatechange = function () {

            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

            alert(xmlhttp.responseText);

            } else {
                //alert("ready state : " + xmlhttp.readyState.toString() + " status : " + xmlhttp.status.toString());
            }
        };

         xmlhttp.send(null);
    }
</script>

我尝试过用Firebug进行调试,但没有效果。XMLHttpRequest对象是为Firefox创建的,它成功地完成了所有代码,但没有响应

<script language="javascript" type="text/javascript">

    function processRequest() {
         var signedURI = "http://api.saaspose.com/v1.0/storage/disc?appSID=myappSID&signature=mySignature";

        var xmlhttp = null;

        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
            if (typeof xmlhttp.overrideMimeType != 'undefined') {
                xmlhttp.overrideMimeType('text/xml');
            }
        } else if (window.ActiveXObject) {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } else {
            alert('Not supported!');
        }

        xmlhttp.open('GET', signedURI, true);

        xmlhttp.onreadystatechange = function () {

            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

            alert(xmlhttp.responseText);

            } else {
                //alert("ready state : " + xmlhttp.readyState.toString() + " status : " + xmlhttp.status.toString());
            }
        };

         xmlhttp.send(null);
    }
</script>

函数processRequest(){
var signedURI=”http://api.saaspose.com/v1.0/storage/disc?appSID=myappSID&signature=mySignature";
var xmlhttp=null;
if(window.XMLHttpRequest){
xmlhttp=新的XMLHttpRequest();
if(typeof xmlhttp.overrideMimeType!=“未定义”){
overrideMimeType('text/xml');
}
}else if(window.ActiveXObject){
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}否则{
警报('不受支持!');
}
open('GET',signedURI,true);
xmlhttp.onreadystatechange=函数(){
if(xmlhttp.readyState==4&&xmlhttp.status==200){
警报(xmlhttp.responseText);
}否则{
//警报(“就绪状态:+xmlhttp.readyState.toString()+”状态:+xmlhttp.status.toString());
}
};
xmlhttp.send(空);
}

你知道为什么Firefox会出现这个问题而IE不会出现这个问题吗?

团队必须通过向WCF服务添加JSONP支持,然后在客户端使用jQuery来解决这个问题,如下所示:

        $(function () {
        $("#disc").click(function () {
            $.getJSON("http://api.saaspose.com/v1.0/storage/disc?appSID=appsid&signature=signature&callback=?", function (data) {
                var items = [];
                $("#discResult").append('<br/><b>Status: ' + data.Status + '</b>');
                if (data.Status = 'OK') {
                    var discUsage = data.DiscUsage;
                    $.each(discUsage, function (key, val) {
                        items.push('<li id="' + key + '">' + key + ': ' + val + '</li>');
                    });

                    $('<ul/>', {
                        'class': 'my-new-list',
                        html: items.join('')
                    }).appendTo('#discResult');
                }
            });
        });
    });
$(函数(){
$(“#光盘”)。单击(函数(){
$.getJSON(“http://api.saaspose.com/v1.0/storage/disc?appSID=appsid&signature=signature&callback=?,函数(数据){
var项目=[];
$(“#discResult”).append(“
状态:”+data.Status+”); 如果(data.Status='OK'){ var discussion=data.discussion; $。每个(磁盘、函数(键、值){ items.push(“
  • “+key+”:“+val+”
  • ”); }); $(“
      ”{ “类”:“我的新列表”, html:items.join(“”) }).appendTo('discResult'); } }); }); });

    谢谢大家的评论。

    什么版本的Firefox?另外,您是否安装了Firebug?你能看到电线上发生了什么吗?你在用firebug调试吗?在这种情况下非常方便。FF版本是9.0.1。我将尝试Firebug并与你们分享结果。谢谢你的建议。我已经试过用Firebug调试,但是没有用。XMLHttpRequest对象是为Firefox创建的,它成功地完成了所有代码,但没有响应。URI和代码与IE配合良好。您确定IE没有缓存以前的响应吗?由于它是一个
    GET
    请求,IE将缓存响应。这意味着它似乎有效,但实际上没有。