The problem was not setting dataType
to JSONP
. Since this was not done, the browser interpreted the call as a standard AJAX request, which meant that it was blocked in the policy with the same source.
Working code for reference (credit refers to @pdeschen for Crpyto offer):
<script type='text/javascript'> // define vars var username = ''; var password = ''; var url = ''; // ajax call $.ajax({ url: url, dataType : 'jsonp', beforeSend : function(xhr) { // generate base 64 string from username + password var bytes = Crypto.charenc.Binary.stringToBytes(username + ":" + password); var base64 = Crypto.util.bytesToBase64(bytes); // set header xhr.setRequestHeader("Authorization", "Basic " + base64); }, error : function() { // error handler }, success: function(data) { // success handler } }); </script>
source share