开发者

Ajax update in a Sharepoint 2010 Webpart

开发者 https://www.devze.com 2023-03-09 04:26 出处:网络
Is there any easy way to make a Ajax call in a Webpart? 开发者_开发技巧I have a Webpart with a button, and I want that when the user pushes the button, it executes a server function without reloadin

Is there any easy way to make a Ajax call in a Webpart?

开发者_开发技巧

I have a Webpart with a button, and I want that when the user pushes the button, it executes a server function without reloading the page. And then, if all is ok, execute a callback function. I thought that the best way is with a AJAX call.

But when I've looked for how to do it I only get some complicated tutorials that I don't really understand (and most are from old versions of Sharepoint). Any help? What is the best way to start? Thanks


Have you tried using jQuery with a content editor web part? I've done this before and it's rather easy. Here is a step by step for how I do it.

  1. Download jQuery.
  2. Upload jQuery to SiteAssets in Sharepoint.
  3. Upload coded file (see below) with AJAX calls.
  4. Point to coded file via Content Editor Web Part.
  5. It should work!

Here is a default way something should work.

<html>
  <head>
    <script src="<point to jquery file>"></script>
    <script type="text/javascript">
      $(document).ready(function(){
        $('#main').load('<RELATIVE URL TO SERVER PAGE>');
      });
    </script>
  </head>
  <body>
    <div id="main"></div>
  </body>
</html>


If possible I would go for a Visual Web Part in Visual Studio. You basically create a .NET user control. It saves you a lot of manual control definitions etc.

If in SharePoint2007 you might want to take a look at the "Smartpart". It has ajax support and some great tutorials on how to use it.

0

精彩评论

暂无评论...
验证码 换一张
取 消