I want to call a Django Rest API in Frontend using Javascript, jQuery, AJAX. Request method is POST but when I see the API call its calling OPTIONS method. So, I came to know about access-control-allow-origin
which needs to be allowed in APIs I guess. For that I used django-CORS-headers
package but still its calling the OPTIONS
method.
code is something like this :
jQuery.ajax({
url: API_url,
headers:headers,
dataType: "JSON",
type: "POST",
crossDomain: true,
xhrFields: {
withCredentials: true
},
success: function( response, jqXHR ) {
do something here
}
});