Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to call Rest Services using javascript. My code is:

C#
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);
     }



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....
Posted

1 solution

I found solution in this article:

Consuming WCF REST Services Using jQuery AJAX Calls[^]
 
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