nekudocom/shiny_geoip

GET request by JavaScript?

beytarovski opened this issue · 0 comments

Hi,

I tried to use simple "get" method in JS, however it returns that error: Origin http://screets.com is not allowed by Access-Control-Allow-Origin.

Here is the code:

var fn_get = function( url, callback ) {

    var self = this,
        xhr = new XMLHttpRequest();

    xhr.open( "GET", url, false );

    // Handle response
    xhr.onreadystatechange = function() {

        if ( xhr.readyState == 4 ) {

            // Perfect!
            if( xhr.status == 200 ) {
                if( callback ) { callback( JSON.parse( xhr.responseText ) ); }

            // Something wrong!
            } else {

                if( callback ) { callback( null ); }
            }
        }
    };

    // Initiate request
    xhr.send( null );

};

fn_get( 'http://geoip.nekudo.com/api/', function(geo) {
    console.log(geo);
});