Monday, August 9, 2010

SP2010 Ajax Issues

Problem:
Ajax is not working as expected in SharePoint 2007.

Solution:
1. First we need to install Ajax extensions on the SharePoint server.
2. After installed Ajax, We need to add the corresponding entries in web.config file to know the web application that the script manage, ajax requests etc... For this we need to change the configuration.
3. Copy all the ajax dlls to GAC and then follow the instructions below.

There are plenty of problems while integrating Ajax into SharePoint when i was very new to SharePoint. I solved those problems after a long research on Masterpage and Java scrpt.

Here are the steps i followed.
Before change any of the file as mentioned below please take the backup of every file and save it in some safe location.

When i was new to learn SharePoint, i implemented this. I am not completly sure that we need to change the authorizedTypes Tag in web.config of my site ot not, but it works.
The changed section looks like below.

Web.Config changes
































Master page changes:
Second, i removed the onload function from BODY tag. This was causing problem, i am not sure that whether we need to remove or not!!! But it's working as expected.

I removed following section from BODY of master page.
onload="javascript:if (typeof(_spBodyOnLoadWrapper) != 'undefined') _spBodyOnLoadWrapper();"

JAVASCRIPT CHANGES:
Third, Go to init.js file in 12\TEMPLATE\LAYOUTS\1033 folder.
find the method spFormOnSubmitWrapper()
in this function, just remove the line return false; in
if (_spFormOnSubmitCalled) statement;
this is because, if that page is already posted back, sharepoint won't post it back again.
but to work AJAX calls, we need to disable it. Because Ajax sends the XmlHttpRequests many times depends on user requests, SharePoint ignore all the calls except the very first call. This is the reason when very first time you integrate Ajax into SharePoint the first call always successful and from the second call no response.
Hope it helps. 

No comments:

Post a Comment

Sharepoint