Link to home
Start Free TrialLog in
Avatar of Isaac
IsaacFlag for United States of America

asked on

ERROR - Ajax Request Error (Origin 'null' is therefore not allowed access.)

I am trying to run the code below
    $(function() {
        var params = {
            "api_key": "{xxxxxxxxxxxxx}"
            // Request parameters
            "StationCode": "{string}"
        };

        $.ajax({
            url: "https://api.wmata.com/Rail.svc/json/jStationParking?StationCode=A09",
            type: "GET",
            contentType: "application/json"
        })
        .done(function(data) {
            //alert("success");
            console.log("success" + JSON.stringify(data) );
        })
        .fail(function() {
            console.log("error");
        });
    });

Open in new window

but I get this error:
User generated image
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

for your web service, it seems that it requires you to pass in the Access Control Allow Origin header.

try:

$.ajax({
            url: "https://api.wmata.com/Rail.svc/json/jStationParking?StationCode=A09",
            type: "GET",
            crossDomain: true,
            contentType: "application/json"
        })
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Isaac

ASKER

Avatar of Isaac

ASKER

Thanks Julian!  That worked.
You are welcome.