4

Hi this is my ajax code

function GetCurrentUserId() {

        return $.ajax({
            type: "GET",
            url: rootUrl + '/api/Common/CurrentDateAndUser',
            dataType: 'json',
            crossDomain: true,          
            success: function (data, textStatus, xmLHttpRequest) {
                return data[0];

            },
            error: function (xhr, ajaxOptions, thrownError) {
                toastr.error('Somthing is wrong', 'Error');
            },



        });

    }

When i run this code in IE Browser then i can see this result from quick watch

enter image description here

See the above image, There have a some cookies value in RequestHeader

But same time if i run my application in Chrome or Firefox

Then i got this result

enter image description here

I can't see any cookies values. Why? Why i can't see the cookie values when i ran my application in Chrome? How to work the ajax call with Chrome and firefox? I have spend one weeks for this work, i can't solve this. and also Stack overflow does not helps yet. Please share your knowledge to me. please dude's .

Even a small sliver of wood can help as a toothpick

Edit

This Question related to my previous question

Web Security in IE VS Chrome & Firefox (bug)

Community
  • 1
  • 1
  • Could you clarify your question a bit more? What is your goal? What did you try? What is the specific code of `CurrentDateAndUser`? Before you get a decent answer you have to ask a decent question. – GuyT May 02 '14 at 12:08
  • Did you already set `async` to false in the ajax call? And use `http://127.0.0.1` instead of `localhost`? Another possible solution is to patch your host file: c:\windows\System32\drivers\etc\hosts add the following: 127.0.0.1 test.mydomain.com Start your webserver within Visual Studio Close all browsers, then load test.mydomain.com – GuyT May 02 '14 at 12:20
  • Yes, Already did, Why that is the problem? But I need proper solution for that dude. I have a headache for this strange issue. (may be a CORS Issue) –  May 02 '14 at 12:21
  • okay wait i will try that. Do you mean i need host my application in IIS ? –  May 02 '14 at 12:22
  • Where are you debugging? Directly in Visual Studio? Normally Visual Studio starts some kind of server.. What's the server address? – GuyT May 02 '14 at 12:24
  • @GuyT Got a error `Bad Request - Invalid Hostname ` –  May 02 '14 at 12:24
  • You've also to take a look at the portnumber(ip + portnumber = socket). – GuyT May 02 '14 at 12:25
  • Do you have anything in document.cookie in Chrome/FF? – ailerifren May 08 '14 at 22:52
  • Browsers should send cookies per default. Can you confirm that you're authenticated in Chrome/FF and have the .ASPX-cookie as @ailerifren suggests? Are you using both http and https at the same time? (That may cause issues if cookies are marked as secure.) – sisve May 10 '14 at 09:09
  • Since your screenshots on your other question, u actually make a CORS request! I refer to this[http://i.stack.imgur.com/EeLye.jpg] screenshot. U access from port 50949 to port 12345! Can u check the headers of the HTTP response in the fiddler and provide them here? – Lux May 13 '14 at 14:58

1 Answers1

1

You need to explicitly tell IE to send the cookies to the server withCredentials: true

e.g.

 $.ajaxSetup({
    type: "POST",
    data: {},
    dataType: 'json',
    xhrFields: {
       withCredentials: true
    }
 });
joepour
  • 6,831
  • 10
  • 32
  • 29