I'm sending an ajax request to a php API that only allows POST requests.
$.ajax({
url: '"//localhost/api/vs_1_0/availability"',
data: $("#api-test").serialize(),
type: "POST",
dataType: "json",
headers: {
"PHP_AUTH_USER": "username",
"PHP_AUTH_PW": "123"
},
success: function (data)
{
alert("Data from Server" + JSON.stringify(data));
},
error: function (jqXHR, textStatus, errorThrown)
{
alert("You can not send Cross Domain AJAX requests: " + errorThrown);
}
});
when i'm sending this request i can see "Cross-Origin Request Blocked: " error in firebug and it won't execute ajax request. I have to send the username and password inside the header for $_SERVER['PHP_AUTH_PW'] and $_SERVER['PHP_AUTH_USER'] variables. It worked by doing a CURL request. But can i send a request to the server via Ajax request. How can i perform this kind of request.