No Access-Control-Allow-Origin error while trying to access REST Webservice from JQuery

3
I am Trying to access a mendix REST Service from jquery and getting the below error http://localhost:8080/rest/validate. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:49224' is therefore not allowed access. The response had HTTP status code 405. Below is my jquery code used to access the WebService jQuery.ajax({ type: 'POST', url: 'http://localhost:8080/rest/validate', contentType: 'application/json', dataType: 'json', data: {"email":'one@user.com', "password":'1234'}, success: function (data) { if(data.Status === true){ alert("Welcome, " + data.UserName); return true; } }, error: function (jqXHR, status) { alert(status); return false; } }); So how can I Set the header with Access-Control-Allow-Origin? Thanks in Advance
asked
1 answers
1

Browser do not allow you to send requests to another hosts (or ports in this case) using XHR than from which the page was served. This doesn't relate to Mendix, but how browsers work. To find out more details about these security mechanisms I suggest diving into the concepts such as 'cross site requests', 'page origin', 'cross site request forgery' and 'jsonp'.

After grasping the meaning of those concepts; headers can be set by using the 'setResponseHeader' java action, but make sure that you are not introducing security risks first. Do not set this header just because the error message suggested you to do so.

answered