1

Continue to receive this as a return for a $.ajax post.

"401 (API requests require HTTP Basic Auth or OAuth.) Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource."

Returns 200 OK with postman or hurl.it.

I have written the following below continue to see the above error. Should I be adding headers under url instead of in the beforeSend, or have I omitted an additional unknown parameter?

This is an ajax POST for http://api.myemma.com/ and the credentials and account ID being used are valid.

 var data = {
    "fields": {
    "first_name": "fname",
    "last_name": "lname",
    "postal_code": "00000"
    },
    "email": "test@testing.com",
},
username = "username",
password = "password",
accountid = "0000000";
$.ajax({
  type: "POST",
  url: "https://api.e2ma.net/"+accountid+"/members/add",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  data: JSON.stringify(data),
  xhrFields: {
    withCredentials: true
  },
  beforeSend:function(xhr){
    console.log("beforesend");
    xhr.setRequestHeader ("Authorization", "Basic " + btoa(username + ":" + password));
  },
  success:function(data){
    alert("success");
  },
  error:function(error){
    console.log(error);
  }
});
VanCoon
  • 310
  • 2
  • 15

0 Answers0