4

I am developing an AngularJS app and I've implemented a simple login API call. The API gives me a response in all browsers except in Safari.

My login API call looks like this

$http.post(config.login, {
        email: username,
        password: password
    })
    .then(function (response) {
            callback(response);
        },
        function (response) {
            callback(response);
        });

I get the following response in Safari.

enter image description here

I am using Angular v1.4.8 a Safari Version 9.0 (11601.1.56)

Any clue on whats going wrong?

Jaseem Abbas
  • 5,028
  • 6
  • 48
  • 73
  • [SYNTAX_ERR: DOM Exception 12 - Hmmm](http://stackoverflow.com/q/7315162/2333214) you probably don't have html5 doctype..? – T J Dec 22 '15 at 06:47

1 Answers1

3

This makes me crazy. First thing, I download angular.js file, then search for "xhr.setRequestHead". All problems are here. I've tried to put some logs to see what was happening.

forEach(headers, function(value, key) {
    key = key.trim();// trim the key
    value = value.trim();// trim the value
    console.log("******************** key: " + key);
    console.log("******************** value: " + value);
    console.log('value: Basic vs ' + value+ ' equal: '+ (value==="Basic"));
    console.log('value.length: ' + value.length);
    if (isDefined(value)) {
         xhr.setRequestHeader(key, value);
    }
});

I found that angularjs automatically put header 'Authorization':'Basic' in. But the length of 'Basic' string is 6 not 5. So using key = key.trim() and value = value.trim() solves problem.

Let me know if this help.