Can I use jQuery ajax in a SharePoint WebPart without having to worry about the same origin policy?
My current project for work involves developing a SharePoint 2007 WebPart which will be deployed by our clients. To provide a better user experience, I am "simulating" ajax via setting the SRC
attribute of an IFRAME
to be the address of an HTTP handler. These handlers are deployed to the layouts direc开发者_如何学Ctory in the 12 hive.
Although this works, I would prefer to use the $get()
method of jQuery. Will this work reliably in my scenario or will I still be subject to the same origin policy? What about the scenario where the WebPart is being deployed to various places on a SharePoint farm? Will there be any problems with using $get()
in that case?
Would the Same Origin Policy prevent me from invoking an HTTP handler using $get
?
By adding the ashx
handlers to the 12\TEMPLATE
folder you are adding the handlers to all sites and sub-sites on your applications. Essentially, you have many copies of them.
If the AJAX call is relative to the domain, for example to /_layouts/foo.ashx
, it will not be affected by the same origin policy.
Other scenarios, where the handlers are installed in a fixed location (e.g. Central Administration), will be blocked by the policy, same as every other page.
The browser implements the same origin policy in normal viewing mode no matter if you are running locally or remotely. The domains must match.
精彩评论