1

I'm currently having issues making an external GET request for an API that I need to call and retrieve data from dynamically in JSON. Does anyone know what below may be incorrect? The main issue seems to be that the header information for the Authentication field is not being set correctly and that javaScript can't call out of local domains. I desperately need a work around to this : (error: XMLHttpRequest cannot load http://www.website.com/api.php. Origin http://localhost is not allowed by Access-Control-Allow-Origin.)

function requestDealer(url)
{
    alert("looking up dealer");
var request = new XMLHttpRequest();

    $.ajax({

        url:url,
        type: 'GET',
        data: null,
        Accept : "application/json",
        contentType: "application/json",
        success: function() { alert('hello!'); },
        error: function() { alert('boo!'); },
        beforeSend: setHeader
    });
 }

 function setHeader(xhr) {
        xhr.setRequestHeader('Authorization', 'NLAuth nlauth_account=23984390, nlauth_email = email@email.com, nlauth_signature= myPwrd');
        xhr.setRequestHeader('Content-Type', 'application/json');
      }
TheCodingArt
  • 3,436
  • 4
  • 30
  • 53
  • 2
    https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS – j08691 Sep 30 '13 at 18:17
  • There have been many, many questions asked on this subject. See: http://stackoverflow.com/questions/10143093/origin-is-not-allowed-by-access-control-allow-origin http://stackoverflow.com/questions/9310112/why-am-i-seeing-an-origin-is-not-allowed-by-access-control-allow-origin-error etc. Searching on stackoverflow can net you a lot more of these, as well. – Ledivin Sep 30 '13 at 18:20
  • possible duplicate of [Ways to circumvent the same-origin policy](http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy) – Bergi Oct 01 '13 at 00:59

0 Answers0