3 Replies Latest reply on Jun 28, 2018 12:53 PM by LucasERAS69

    PI Web API CORS stop me on some preflighted request.

    LucasERAS69

      Hello,

       

      I've been stumped by this issue for quite some time. When I click on a button, I wish to change the value of an attribute according to the value written by the user in a text field. To do that I execute a GET which fetch the selected attribute, then execute a POST which is supposed to change the value. The problem is, I get an error code 500 along with a message telling me I do not have the Access-Control-Allow-Origin header.

       

      Here's my settings

      Setting.png

      And here's the script activated by my button

      Code.png

       

      I'm not sure what the red strip is.Anyway, I've also tried to put "plain/text" and "text" into contentType and dataType but to no avail. When the page load, I fetch all attributes of the element "Web test" with a serie of GET. I don't see why those work while my request here doesn't.

        • Re: PI Web API CORS stop me on some preflighted request.
          awoodall

          In your CorsMethod configuration, try changing OPTION to OPTIONS? In my test with OPTION I got a message about "No 'Access=Control-Allow-Origin' header..." as well, although I got 400 instead of 500 error. If it doesn't help, a screenshot of the error message in the developer tools console in your browser would be helpful.

            • Re: PI Web API CORS stop me on some preflighted request.
              LucasERAS69

              Nothing changed, unfortunatly.

               

              The error is in french but the closest translation I could find was

              Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at [url]. This can be fixed by moving the resource to the same domain or enabling CORS.

              It also tell me it's because the header Access-Control-Allow-Origin is missing.

              But as far as I can tell, I've already enabled CORS, and the API should send the correct header.

               

              P.S:

              I'm working on Firefox and here's the message in Chrome:

              Failed to load<url>: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 400.

               

              Note that the status code is 400 instead of 500 on Chrome.

            • Re: PI Web API CORS stop me on some preflighted request.
              LucasERAS69

              I have resolved my issue.

               

              By using jquery $.post() the request is accepted. However, I need to put "Json" as the datatype.
              So the correct request would be: $.post(url, value, functionOnSucess(), "Json"). It's exactly the same thing for get request: $.get(url, functionOnSuccess(), "Json").