locked
$.ajax is working in IE9/IE10 but not working in firefox RRS feed

  • Question

  • User2078978235 posted

    Hi,

    I am calling WCF service(REST) and response is coming in json format. I am accessing cross domain service.

    My problem is that when I run into firefox and debugg in firebug, it shows request status is aborted. seems like it doesnot suport "CORS".

    I have done google from last 3 days to get rid of this. but at last I am posting it here.

    my code are:

    var methodParams = '{"userName":"' + userName + '","password":"' + password + '"}';
                $.support.cors = true;
                $.ajax({
                    type: 'POST',
                    url: "https://mydomain/mywcfservice.svc/Method",
                    data: methodParams,
                    contentType: 'application/json; charset=utf-8',
                    dataType: "json",
                    success: function (response, status, xhr) { alert('success: ' + JSON.stringify(response)); },
                    error: function (xhr, status, error) { alert("Error\n-----\n" + xhr.status + '\n' + xhr.responseText); },
                    complete: function (jqXHR, status) { alert('Status: ' + status + '\njqXHR: ' + JSON.stringify(jqXHR)); }
                });
    Wednesday, March 13, 2013 8:11 AM

Answers

All replies

  • User281315223 posted

    CORS-support is based on the browser and you can't "force" the brower to use it if it isn't supported (but this shouldn't be an issue in Firefox).

    The $.support.cors jQuery code just returns if the browser actually supports CORS or not (I don't believe that it actually enables it). You'll also need to ensure that you are including the appropriate  "Access-Control-Allow-Origin: *" Http Header within your Requests.

    Have you tried adding the crossDomain property to your $.ajax call (not sure if this will even work) : 

    crossDomain: true

    This Stack Overflow discussion might help shed some more light (it's discussing cross-domain ajax requests). Here's another as well.

    Wednesday, March 13, 2013 6:07 PM
  • User2078978235 posted

    Rion Williams

    The $.support.cors jQuery code just returns if the browser actually supports CORS or not (I don't believe that it actually enables it).

    I also dont believe that $.support.cors enable it. but when I chek it using following code in IE 9/10 It first return false and then true.:)

    in mozila it both the alert says "true".

                alert($.support.cors);//this line return false
                $.support.cors = true;
                alert($.support.cors);//this line return true
                $.ajax({
                });

    Rion Williams

    Have you tried adding the crossDomain property to your $.ajax call (not sure if this will even work) : 

    crossDomain: true

     I already tried.

    Rion Williams

    You'll also need to ensure that you are including the appropriate  "Access-Control-Allow-Origin: *" Http Header within your Requests.

    Are you sure that I need to add it in Request Header, I think it came from Respose Header from server. and server must cors enabled.
     

    Thursday, March 14, 2013 2:51 AM
  • User281315223 posted

    I believe I had mistyped and you are correct it should be the Response Header.

    You may want to try taking a look at this discussion on Stack Overflow regarding using Cross-Domain Requests in Firefox and some possible suggestions that may help you out.

    One of the proposed methods is using the ForceCORS add-in, which may be useful to test with to check if it is working at all.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 14, 2013 8:41 AM