javascript - Same origin policy problem calling sharepoint web service -
javascript - Same origin policy problem calling sharepoint web service -
i trying phone call pre-defined web services sharepoint server unable due same origin policy problem , cannot find solution it. tried setting document.domain server name , server port instead throws dom security error 18 same problem previous error. trying phone call getlists method test whether works , code taken tutorial have seen online here. help much appreciated. in advance.
my code follow:
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.1.js" type="text/javascript"></script> </head> <body> <div> <script type="text/javascript"> $(document).ready(function () { document.domain = 'http://servername:serverport' var soapenv = "<soapenv:envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \ <soapenv:body> \ <getlistitems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \ <listname>occupations</listname> \ <viewfields> \ <viewfields> \ <fieldref name='title' /> \ </viewfields> \ </viewfields> \ </getlistitems> \ </soapenv:body> \ </soapenv:envelope>"; // phone call web service $.ajax({ url: "http://servername:serverport/_vti_bin/lists.asmx", type: "post", datatype: "xml", data: soapenv, complete: processlistaccessresult, contenttype: "text/xml; charset=\"utf-8\"" }); }); // process result function processlistaccessresult(xdata, status) { $(xdata.responsexml).find("z\\:row").each(function () { $("#data").append("<li>" + $(this).attr("ows_title") + "</li>"); }); } </script> <ul id="data"></ul> </div> </body> </html>
with ajax, pages , info must come same top level domain. there few ways around this:
actually utilize same domain serve pages , xml data. use proxy on server xml remote domain, , re-serve same domain pages. lower security on browser(s), or perhaps add together sites listed sites. (never tried myself it's alternative unless it's intranet or something) use jsonp instead of xml (this works around cross domain policy) use yahoo pipes or yql convert xml jsonp like example javascript sharepoint same-origin-policy
Comments
Post a Comment