Click here to Skip to main content
15,860,859 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to call my webservice (cross domain service) using Jquery.
But $.support.cors = true; is working fine in IE8 , but not in chrome and firefox.
Please help me to resolve this issue.

XML
<script   src= "jquery-1.9.1.js"></script>
<script src ="jquery-1.9.1.min.js"></script>
    <script language ="javascript" type="text/javascript">
         function Do() {
             $.support.cors = true;            
            $.ajax({
                type: "Get",
                url: "url", // Location of the service
                data: '{"parameter"="value"}', //Data sent to server
                contentType: "application/json;charset-uf8", // content type sent to server
                dataType: "xml", //Expected data format from server
                success: function(msg) {
                    //Implement get data from service as you wish
                    alert("Success");
                },
                error: function(err) {
                    // When Service call fails
                    alert("error");
                }
            });
        }
    </script>



[Moved From Answer Box]
I am getting same error, even when i try access the data from the same domain.
JavaScript
function Do() {
            $.support.cors = true;        
            $.ajax({
                type: "GET",
                url: "test.xml",
                dataType: "xml",
                data: "",                               
                headers: { 'Accept': 'text/xml' },
                headers: { 'Access-Control-Allow-Headers': 'application/json; charset=utf-8' },            
                error: function(xml) { alert(xml.text); },
                success: function(xml) {
                    alert("success");                
                    spnid.innerHTML = xml.text;
                }
            });
        }
Posted
v2

1 solution

Try this
JavaScript
function GetData() {
    var ServiceUrl = "";

    var content = '';
    $.support.cors = true;
    $.ajax({
        type: 'GET',
        url: ServiceUrl,
        async: true,
        cache: false,
        crossDomain: true,
        contentType: "application/json; charset=utf-8",
        dataType: 'json',
        error: function (xhr, err) {
     
        },
        success: function (data) {
          
        }
    });


Hope this helps
 
Share this answer
 
Comments
Member 8112455 6-Mar-13 1:11am    
Thank you for sharing the code. But still i am getting the error.

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