I'm trying to login to moodle from an external webpage using a post form to moodle, I used the next ajax to send the inputs:
var frm = $('#loginForm');
frm.submit(function(e) {
e.preventDefault();
$.ajax({
type: frm.attr('method'),
url: frm.attr('action'),
data: frm.serialize(),
xhrFields:{
withCredentials:true
},
async:true,
beforeSend: function (xhr){
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
},
success: function (data) {
console.log("Logged");
},
error: function (data) {
console.log("NOT Logged");
},
});
});
Now into the moodle's login/index.php I insert the headers to make possible the CORS connection:
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Origin: http://fabianmurillo.000webhostapp.com");
header("Origin" : "http://fabianmurillo.000webhostapp.com");
When I run the code, the browser returns an error:
..preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin'..
Dunno why browser is blocking the connection for login to moodle.
Thanks for your help.