页面方法调用jQuery的,从到SharePoint [英] Page Method calls from jQuery to Sharepoint

查看:101
本文介绍了页面方法调用jQuery的,从到SharePoint的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经部署在MS的SharePoint的 _layouts 文件夹中的应用程序页面(ASPX)2010。

我想打电话标有使用jQuery的 [的WebMethod] 属性,该属性页面中的方法。我使用下面的code对的document.ready()

  $(#btnOk)。点击(函数(){
    VAR theUrl ='/_layouts/MyProject/MyPage.aspx/MyMethod';
    $阿贾克斯({
        键入:搞定,
        数据类型:JSON
        网址:theUrl,
        数据:{},
        成功:函数(响应){
            [...]
        },
        错误:功能(XHR,textStatus,errorThrown){
            [...]
        }
    });
});

这code遗憾的是不工作的。问题是与URL:其实它的工作原理,如果我使用绝对URL像这样

  VAR theUrl =HTTP://server/sites/xxx/_layouts/MyProject/MyPage.aspx/MyMethod';

如何变换绝对的我的去路?


解决方案

  / _布局/ MyProject的/ MyPage.aspx /的MyMethod

在你的例子是等价于:

  HTTP://server/_layouts/MyProject/MyPage.aspx/MyMethod

这是你的问题。与/开始指从根开始。你应该调整这一点。如果它必须以某种动态的,因为它可以用于多个地方,可能需要使用codebehind注入路径或东西。如果总是从一个静态的地方跑,只需要修改URL。

如果你从运行它的页面,例如:

  HTTP://server/sites/xxx/Somepage.aspx

然后,只需将其更改为

  _layouts / MyProject的/ MyPage.aspx /的MyMethod

不带斜线。

如果你是在一个子文件夹,例如:

  HTTP://server/sites/xxx/Pages/Somepage.aspx

那么你可以这样做:

  ../_布局/ MyProject的/ MyPage.aspx /的MyMethod

在..将您的文件夹。

I have an application page (aspx) deployed in the _LAYOUTS folder of MS SharePoint 2010.

I would like to call a method inside that page marked with the [WebMethod] attribute using jQuery. I am using the following code on document.ready():

$("#btnOk").click(function () {
    var theUrl = '/_layouts/MyProject/MyPage.aspx/MyMethod';
    $.ajax({
        type: "get",
        dataType: "json",
        url: theUrl,
        data: {},
        success: function (response) {
            [...]
        },
        error: function (xhr, textStatus, errorThrown) {
            [...]
        }
    });
});

This code unfortunately does not work. The problem is with the URL: in fact it works if I use an absolute URL like this

var theUrl = 'http://server/sites/xxx/_layouts/MyProject/MyPage.aspx/MyMethod';

How can I transform my path in an absolute one?

解决方案

/_layouts/MyProject/MyPage.aspx/MyMethod

in your example is equivalent to:

http://server/_layouts/MyProject/MyPage.aspx/MyMethod

that is your problem. starting with / means start at the root. You should adjust this. If it has to be somehow dynamic because it can be used multiple places, you may need to use the codebehind to inject the path or something. If this is always run from a static place, just modify the url.

If the page you're running it from is, for instance:

http://server/sites/xxx/Somepage.aspx

Then just change it to

_layouts/MyProject/MyPage.aspx/MyMethod

with no slash.

If you are in a subfolder, for instance:

http://server/sites/xxx/Pages/Somepage.aspx

then you can do this:

../_layouts/MyProject/MyPage.aspx/MyMethod

the .. will take you up one folder.

这篇关于页面方法调用jQuery的,从到SharePoint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆