Jump to content
Ultimaker Community of 3D Printing Experts

Cross-Domain error when using the API with Ajax


Recommended Posts

Posted (edited) · Cross-Domain error when using the API with Ajax

Hi,

I'm currently trying to use the API to control remotely my Ultimaker 3 with a webpage.

So, I use Ajax to make a request on the printer but it won't allow me to make the request.

For the moment I try to check the validity of the id :

function checkTicket(ticketId) {
            $.ajax({
                    type: 'GET',
                    url: 'http://192.168.1.120/api/v1/auth/check/' + ticketId,
                    contentType: 'application/json',
                    headers: {
                        'Accept': 'application/json'
                    }
                }
            ).done(function (data, textStatus, jqXHR) {
                console.log(data);
                switch (data.message) {
                    case "authorized":
                        break;
                    default:
                        requestTicket(user.name);
                        break;
                }
            }).fail(function (jqXHR, textStatus, errorThrown) {
                console.log(jqXHR);
            });

But I got an error :

Quote

Failed to load http://192.168.1.120/api/v1/auth/check/c6c71b01f5b5292c6261632ae2xxxxxx: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1' is therefore not allowed access.

 

My request headers :

Accept:*/*
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.9
Access-Control-Request-Headers:content-type
Access-Control-Request-Method:GET
Cache-Control:no-cache
Connection:keep-alive
DNT:1
Host:192.168.1.120
Origin:http://127.0.0.1
Pragma:no-cache
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36

 

Thanks for your help !

Edited by PeakyBlinders
  • Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
     Share

    • Our picks

      • New here? Get ahead with a free onboarding course
        Hi,
         
        Often getting started is the most difficult part of any process. A good start sets you up for success and saves you time and energy that could be spent elsewhere. That is why we have a onboarding course ready for
        Ultimaker S5 Pro Bundle, Ultimaker S5, Ultimaker S3 Ultimaker 2+ Connect.   
        They're ready for you on the Ultimaker Academy platform. All you need to do to gain access is to register your product to gain free access. 
        Ready? Register your product here in just 60 seconds.
          • Like
        • 11 replies
    ×
    ×
    • Create New...