Learn, Share, Build

211
October 05, 2017, at 2:35 PM

I am making a POST request to AWS s3 API gateway using JQUERY & AJAX. Upon submit, the shadow is updated. However I get an error in the console. Here is the ajax part of the code,

var myJSON = JSON.stringify(obj);
$.ajax({
   type: "POST",
   url:  "<aws-url>" ,
   data: myJSON,
   crossDomain : true,
   //dataType: 'jsonp',
   headers :{
            'Content-Type':'application/x-www-form-urlencoded'
            },
   success: function(result) {
        console.log("done");
   }
});

The POST works and the shadow is updated, but I still get this error at the console. Also I am aware that postman can't be used with POST method. Here is the error: Failed to load :No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://s3-ap-southeast-1.amazonaws.com' is therefore not allowed access.

I don't understand whats going on. Please help!!

Answer 1

Please enable CORS in you API gateway like below.

If you don't have OPTIONS added, please follow below steps (If OPTIONS already there just add CORS),

  • Create a new OPTIONS method under the /services resource
  • Create and populate the Access-Control-Allow-Origin/Method/Headers in the OPTIONS method.

Enable CORS like below after creating OPTIONS

READ ALSO
Learn, Share, Build

Learn, Share, Build

I found this nice script, by Bitwise Creative, to change the color of a numeric content by the value

207
Learn, Share, Build

Learn, Share, Build

Please help meHow can I add a button in the following jQuery DataTable?

264
Learn, Share, Build

Learn, Share, Build

I have written following code for validation of date

137
Learn, Share, Build

Learn, Share, Build

I created a addEventListener and want to send the event to another function so it handles itBut i keep getting this error(on firefox browser):

187