I’m trying to authenticate to an API, which only allows you to authenticate using a POST with JSON as form data, in the format of
{"username":"myusername","password":"mypassword"}
I’ve been trying for three days to get this working with jQuery but I’m running into problems because it’s cross domain. How can I accomplish this?
Error message:
"NetworkError: 405 Method Not Allowed
My Code:
var username = "myusername";
var password = "mypass"
var authurl = "https://myurl";
$.ajax
({
type: "POST",
url: authurl,
dataType: 'json',
contentType: "application/json",
async: false,
data: {'json':'{"username":"' + username + '", "password":"' + password + '"}'},
success: function (result) {
$('#json').html(result);
}
})
I had same issues but I use
dataType:jsonpit worked for me.Here is jQuery Docs for more details