views:

78

answers:

3

Hi everybody, I need to code a webpart which purpose is to asynchronously fetch some documents and display them into an existing page. Unfortunately I have to face a lot of rescritcions and my struggle to find a solution seems useleess so far.

1) I cannot use Microsoft asp.net ajax
2) I must use Jsonp because the called service (page, whatever...) is outside the site's domain. That's not a big problem.
3) I have no possibility to alter the existing page code, so I cannot reference an external library such as JQuery.
4) For the same reason I have no possibility to call my methods on the window.onLoad event, so here the question is: how can I be sure that everything is correctly loaded before triggering my ajax call?
5) Since several instances of the same webpart can be placed into the same page, can there be some possible conflicts among the various js functions?

+1  A: 
  1. D'oh
  2. D'oh #2
  3. jQuery is just a wrapper for native JavaScript calls. If you can, get them to waive this restriction because if you're doing anything remotely complex you're going to go insane over browser compatibility.
  4. Use _spBodyOnLoadFunctionNames.push(functionName) to accomplish this.
  5. Depends entirely on the JS coming in. We'd need more clarification.
zincorp
+1  A: 

Can't you just call the 3rd party page using server-side code (e.g., WebClient)? You may have to adjust the site's trust levels for this.

For client-side, I believe you can still "inject" the jQuery code into the markup. http://stackoverflow.com/questions/1014203/best-way-to-use-googles-hosted-jquery-but-fall-back-to-my-hosted-library-on-goo

<script type="text/javascript">
if (typeof jQuery == 'undefined')
{
    document.write(unescape("%3Cscript src='/path/to/your/jquery' type='text/javascript'%3E%3C/script%3E"));
}
</script>
Vince
Thank you for the hint. I'll try to see if all goes fine by doing the inclusion in the body.
mamoo
+1  A: 

What about using a page viewer web part to display the page that is hosted elsewhere (ie not on your SharePoint server)? That page could retrieve the documents for you.

Paul Lucas
That could be a good option. Thank you!
mamoo