0

I am currently trying to get a simple demo going of a crud app using the public OData feed at http://services.odata.org/V4/(S(jskq43fsvrxbzaf2jzhboo13))/OData/OData.svc/Products

GET-ting data works, however I am unable to update the data by clicking the button, and get a 501 (Not Implemented) error. I believe it deals with the need to enable CORS. Please see my fiddle. Thanks in advance!

var requestSettings = {
  url: "http://services.odata.org/V3/(S(ettihtez1pypsghekhjamb1u))/OData/OData.svc/Products(" + key + ")",
  method: "POST",
  headers: {
    "X-Http-Method": "PATCH",
    'accept': "application/json;odata=verbose"
  },
  'contentType': "application/json; charset=utf-8", //content-length not required
  datatype: 'json',
  data: JSON.stringify(values),
  success: function updateSuccess() {
    deferred.resolve();
    alert("successful update");
  },
  error: function updateError() {
    deferred.reject();
    alert("un-successful update");
  }
};

$.ajax(requestSettings);

I have a JSFiddle here: https://jsfiddle.net/jf713jf/ybLg1b4h/4/

Jon Friedman
  • 64
  • 1
  • 10
  • If anyone else is having the same CORS-issue with the TripPin service: consider upvoting with and following https://github.com/OData/ODataSamples/issues/29. – Boghyon Hoffmann Feb 07 '21 at 21:19

1 Answers1

0

Consider to use DevExpress.data.ODataStore that provides logic to access OData service.

Since you're working with fourth version of OData service, the ODataStore constructor options would like that:

new DevExpress.data.ODataStore({
    url: "http://services.odata.org/V4/(S(jskq43fsvrxbzaf2jzhboo13))/OData/OData.svc/Products",
    key: "ID",
    keyType: "Int32",
    version: 4,

    // To overcome the cross-origin issue
    jsonp: true
});

Hope it helps.

seteh
  • 389
  • 4
  • 13
  • Thanks, but that isn't working. I switched over to using the ODataStore, but I am still getting the same 501 error in the console. Please see the JSBin I have posted above. Thanks! – Jon Friedman Jun 24 '15 at 14:31
  • I know. It's because OData guys are now working only for fourth and WebAPI version. So I suggest you test your code on the newest version of OData 4 service example: TripPin service. Take a look: http://jsfiddle.net/Seteh/x7uL2myn/ – seteh Jun 24 '15 at 15:22
  • Ok, I'm using that service now. Now when I send the update, I get "No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://null.jsbin.com' is therefore not allowed access. The response had HTTP status code 400." and if I include 'Access-Control-Allow-Origin': 'http://jsbin.com' the response is: Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers. – Jon Friedman Jun 24 '15 at 15:56
  • Appreciate the fiddle, but I just opened it and it's getting the same 400 error when I try sending the update. – Jon Friedman Jun 24 '15 at 16:16
  • @JonFriedman It works fine for me: http://jsbin.com/wujapimete/edit?html,js,console,output – seteh Jun 25 '15 at 09:37
  • thanks but same 400 error, in Chrome and IE. I guess I will have to try from a home computer tonight, it could be the firewall I'm behind if it's working for you. – Jon Friedman Jun 25 '15 at 13:45