"Access Denied" with Rest.svc and jquery ajax from SharePoint

  • 16 December 2013
  • 2 replies
  • 2 views

Badge +8

Greetings,


I'm trying to put a select dropdown on a SharePoint page to action a task. I want to use the Rest.svc since I don't have access to any server side code. Initially, I'm trying to get the list of actions to populate the select, but I'm getting "Access Denied" errors which I believe are stemming from the cross domain nature of this activity (SharePoint to the K2 server...)


Here's my function. What am I doing wrong? I've been trying to follow instructions from the following sites. http://www.k2underground.com/blogs/k2/archive/2012/05/10/integrating-k2-client-events-with-dynamics-crm-2011-using-k2-services.aspx and http://help.k2.com/en/k2u.aspx?DefaultFilters=%26Filter_Product%3D0010%26Filter_Channel%3D0100 and http://cyclops.nettrends.nl/blog/2011/04/k2-and-jquery-creating-a-simple-worklist/#more-342


function getActions(sn){
 var K2URL = K2Server + "/K2Services/REST.svc/Worklist/Items(" + sn + "/Actions?$format=json'";
 
 $.support.cors = true;
 $.ajax({
  url:K2URL,
  method: 'GET',
  contentType: "application/json; charset=utf-8",
  dataType: 'JSON',
  async: true,
  headers: {"X-Requested-With": "XMLHttpRequest"},
  crossDomain: true,
  error: function (data, error, status) {
   alert(status);
   alert(JSON.stringify(data));
  },
  success: function (data) {
   PopulateWorkflowDropDown(data);
  }
 });


2 replies

Badge +8

So I'm partly figured out...


According to this page http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx #7 since I'm crossing from https on sharepoint to http on K2, I'm getting the access denied.


So I tried to access from http on sharepoint, but now the response is simply error, 500.


One other lingering question I have.. the web service for the Worklist needs to know who you are. IE passes the credentials when I go to the URL directly, but what is javascript passing? Does IE pass the NTLM authentication (intranet zone) as part of the javascript request?


Thanks.,


Doug

Badge +8

Well.. still in the http only world.. but typos have an impact ;-)


Here's my working function. I didn't close the ) around the serial number and there was a ' after json.


function getActions(sn){
 var K2URL = K2Server + "/K2Services/REST.svc/Worklist/Items(" + sn + ")/Actions?$format=json";
   
 $.support.cors = true;
 $.ajax({
  url:K2URL,
  method: 'GET',
  type:'json',
  async: true,
  crossDomain: true,
  error: function (data, error, status) {
   alert(status);
   alert(JSON.stringify(data));
  },
  success: function (data) {
   PopulateWorkflowDropDown(data);
  }
 });


Now to go back to ssl...

Reply