Witam,
Mam juz zrobione REST API, i teraz chcialbyl napisac przykladowa aplikacje ktore bedzie wykorzystywac to API.
function Product()
{
var self = this;
self.produktURI = 'http://localhost:55873/api/v0/Produkt';
self.API_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;
self.ajax = function (uri, method, data) {
var request = {
url: uri,
type: "GET",
contentType: "application/json",
accepts: "application/json",
dataType: 'json',
data: JSON.stringify(data),
beforeSend: function (xhr) {
console.log("SENDING!!!");
xhr.setRequestHeader("Authorization",
"Basic " + self.API_KEY);
},
error: function (jqXHR) {
console.log("ajax error " + jqXHR.status);
}
};
return $.ajax(request);
}
self.get = function (product) {
self.ajax(self.produktURI, "GET").done(function (data) {
for (var i=0;i< data.products.length;i++)
{
console.log(data.produkts[i].productID);
}
});
}
}
Niestety wywali mi blad :
OPTIONS http://localhost:55873/api/v0/product 405 (Method Not Allowed)
Jakies sugestie ?
Dzieki