I try to access a sharepoint list via Jquery and REST Interface. The Site with the code below is running localhost.
This code doesn't work:
$(document).ready(function() { getdata(); });
function getdata() {
alert("start");
$.ajax({
url: "http://spkerberostest.vz.ch/_vti_bin/ListData.svc/Tasks",
dataType: 'JSON',
success:function(json) { alert ("Success");
},
error:function(){
alert("Error");
}
});
};
I get the Error Message "Origin http://localhost:59936 is not allowed by Acess-Control-Allow-Origin."
I'm not sure what the reason is. Is it the fact that Sharepoint needs Authentication (anonymous is blocked) or is it the cross-domain call? Or even both?
What can I do? I read somewhere about JSONP as Data Type. But this didn't work. Thanks.
Use the Get Items from SharePoint action in Flow and then use the "Parse JSON" action against the value retrieved from the JSON column. That should give you the data you are after. Hope it helps!
To use the REST capabilities that are built into SharePoint, you construct a RESTful HTTP request by using the OData standard, which corresponds to the client object model API you want to use. The client. svc web service handles the HTTP request and serves the appropriate response in either Atom or JSON format.
REST API provides a flexible, lightweight way of interacting with SharePoint remotely by using any technology that supports REST protocol. With SharePoint API, you can easily perform basic Create, Read, Update, and Delete (also known as CRUD) operations.
Assuming that both of these resources are internal to your company, and you always access one from the other, your Sharepoint administrator could try to turn on what are called CORS (Cross Origin Resource Sharing) headers on the Sharepoint IIS servers.
This will allow your cross-origin calls to complete successfully, as the browser and the servers exchange headers requesting cross-origin sharing. You can learn more about CORS at http://enable-cors.org/
In regards to 3nigma's answer. Jquery's crossDomain flag won't work, because the Sharepoint services aren't designed as JSONP services, which is what Jquery attempts to use when you set that flag. (The Sharepoint server would have to pad the data like it was a Javascript file with a single JSON object in it, but I don't know of a way to configure it to do that.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With