locked
Ajax - Post with ISA Authentication from JavaScript

    Question

  • Our web service is behind an ISA server which is used for users to enter their windows credentials for authentication. I would like to call the web service from JavaScript.

    I am using the following script but am not able to capture the authentication cookie. Within the success/error or complete methods the status is always 0 and according to fiddler the return value is 302

    I have logged in manually and i constructed the same post via ajax but i am not able to complete the call with any success. Status is always 0 and error is thrown but with 'error' text.

    What would i be doing wrong? Is this possible?

    function go(){
            var url = 'https://domain.com/CookieAuth.dll?Logon';
    
        var formData = {            
            curl: "Z2F",
            flags: 0,
            forcedownlevel: 0,
            formdir: 6,
            trusted: 0,         
            username: "domain\\username",
            password: "password",
            SubmitCreds: 'Log On'
        }; 
        $.ajax({
            url : url,
            type: "POST",
            crossdomain: true,
            headers:{
                Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
            },
            data: formData,
            contentType:" application/x-www-form-urlencoded",
            success: function(data, textStatus, jqXHR)
            {
                var cookie = jqXHR.getResponseHeader('Set-Cookie'); //cookie is always null
    
            },
            error: function (jqXHR, textStatus, errorThrown)
            {
                var cookie = jqXHR.getResponseHeader('Set-Cookie'); //always null
                alert('error:' + textStatus + ' ' + errorThrown);
            },
            complete: function (jqXHR, status) {
                if (jqXHR.status === 302) { //status is always 0
                }
                var cookie = jqXHR.getResponseHeader('Set-Cookie'); //Set-Cookie
                alert(jqXHR.status);
            }
        });
    
        $('#mydiv').html('hello');
    };


    dave

    Thursday, December 26, 2013 3:30 PM

Answers

All replies