Quantcast
Channel: Cocos Forums - Latest topics
Viewing all articles
Browse latest Browse all 17076

[Question] how to work basic auth getXMLHttpRequest at Firefox and Chrome

$
0
0

@shingo_izumi wrote:

I want to basic auth with getXMLHttpRequest .

iOS and Simulator(cocoscreator) work!

but It can't work in Browser(Firefox and Chrome) .

I make this code↓↓↓↓

    var xhr = cc.loader.getXMLHttpRequest();
    xhr.onreadystatechange = function() {
    switch ( xhr.readyState ) {
    case 0:
        console.log( 'uninitialized!' );
        break;
    case 1:
        console.log( 'loading...' );
        break;
    case 2:
        console.log( 'loaded.' );
        break;
    case 3:
        console.log( 'interactive... '+xhr.responseText.length+' bytes.' );
        break;
    case 4:
        if( xhr.status == 200 || xhr.status == 304 ) {
            var data = xhr.responseText; // responseXML  is ok
            console.log( 'COMPLETE! :'+data );
        } else {
            console.log( 'Failed. HttpStatus: '+xhr.statusText );
        }
        break;
        }
    };

    xhr.open('GET', 'http://example/index.php', true);
    xhr.setRequestHeader("Authorization", "Basic " + Base64.encode("id" + ":" + "pass"));
    xhr.send();

I used Base64 made by third-party →here(http://www.webtoolkit.info/javascript_base64.html#.V9J8TZOLSV4)

If there is a solution, please please tell me

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 17076

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>