在chrome和firefox中状态为零 [英] status is zero in chrome and firefox

查看:80
本文介绍了在chrome和firefox中状态为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用JavaScript致电Rest Services.我的代码是:

I have to call Rest Services using javascript. My code is:

function CreateXMLHttpRequest() {
         if (typeof XMLHttpRequest != "undefined") {

             return new XMLHttpRequest();
         }
         else if (typeof ActiveXObject != "undefined") {

             return new ActiveXObject("Microsoft.XMLHTTP");
         }
         else {
             throw new Error("XMLHttpRequestnot supported");
         }
     }
     function CallWebService() {
        objXMLHttpRequest = CreateXMLHttpRequest();
       objXMLHttpRequest.open("POST", "http://www.rest.net/services/abc.svc/json/GetXml", true);
       objXMLHttpRequest.setRequestHeader("Content-Type", "application/xml;charset=UTF-8");
         var packet = '<?xml version="1.0" encoding="utf-8" ?><CompanyRequest xmlns="http://schemas.datacontract.org/2004/07/abc.DomainModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><CompanyName>company</CompanyName></CompanyRequest>';
         objXMLHttpRequest.onreadystatechange = function () {

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

                alert(objXMLHttpRequest.responseText);
             }
         }
         objXMLHttpRequest.send(packet);
     }




在IE中的状态是200,我能够得到回应.但是在firefox和Chrome中,状态为0.如何克服这个问题提示我...以及如何解析此响应

在此先感谢....




status is 200 in IE and i am able to get response. But in firefox and Chrome the status is 0. How can i overcome this problem suggest me...and also how can i parse this response

Thanks in advance....

推荐答案

我在本文中找到了解决方案:

使用jQuery AJAX调用消费WCF REST服务 [ ^ ]
I found solution in this article:

Consuming WCF REST Services Using jQuery AJAX Calls[^]


这篇关于在chrome和firefox中状态为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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