Jquery “错误”;PageMethods未定义“;在Sharepoint 2010的Web部件中
我的sharepoint 2010 Web部件中出现PageMethods未定义javascript错误。 基本上,我已经创建了显示谷歌地图的Web部件。单击GoogleMap的标记后,我想调用服务器端事件。我已经为同样的问题实现了jquery。我正在使用PageMethods调用服务器方法。下面是我从一些博客网站上获取的代码。我还在页面上添加了scriptmanager标记,并将EnablePageMethods属性设置为true 脚本块:Jquery “错误”;PageMethods未定义“;在Sharepoint 2010的Web部件中,jquery,ajax,Jquery,Ajax,我的sharepoint 2010 Web部件中出现PageMethods未定义javascript错误。 基本上,我已经创建了显示谷歌地图的Web部件。单击GoogleMap的标记后,我想调用服务器端事件。我已经为同样的问题实现了jquery。我正在使用PageMethods调用服务器方法。下面是我从一些博客网站上获取的代码。我还在页面上添加了scriptmanager标记,并将EnablePageMethods属性设置为true 脚本块: <script src="http://aja
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
// Initialization
$("#ajax_loading_image").hide();
// mousemove event
$().mousemove(function (e) {
window.status = e.pageX + ', ' + e.pageY;
});
// hook up the click event
$("#execute_page_method").click(function () {
$("#message").text("I'm working...");
$("#ajax_loading_image").show("fast");
$("#execute_page_method").hide("fast");
// Call some page method...
PageMethods.ProperMethodName("string", function (result, userContext, methodName) {
$("#ajax_loading_image").hide("slow");
$("#execute_page_method").show("slow");
if (result.Success == true) {
alert("true");
$("body").css("background", "#CAFFD8");
}
else {
$("body").css("background", "#CAFFFF");
}
$("#message").text("This took me " + result.Time + " milliseconds... ");
});
return false;
});
});
</script>
<div>
<a id="execute_page_method" href="http://jquery.com/">Click!</a>
</div>
Code Behind events:
public class MethodReturnedValue
{
public int Time { get; set; }
public bool Success { get; set; }
}
[WebMethod(true)]
public static MethodReturnedValue ProperMethodName(string param)
{
Random random = new Random();
MethodReturnedValue retVal = new MethodReturnedValue();
retVal.Time = random.Next(5000);
Thread.Sleep(retVal.Time);
if (random.Next() % 2 == 0)
{
retVal.Success = true; ;
}
else
{
retVal.Success = false;
}
return retVal;
}
$(文档).ready(函数(){
//初始化
$(“#ajax_加载_图像”).hide();
//鼠标移动事件
$().mousemove(函数(e){
window.status=e.pageX+','+e.pageY;
});
//连接click事件
$(“#执行_页面_方法”)。单击(函数(){
$(“#消息”).text(“我正在工作…”);
$(“#ajax_加载_图像”).show(“快速”);
$(“执行页面方法”).hide(“快速”);
//调用某个页面方法。。。
PageMethods.ProperMethodName(“字符串”、函数(结果、用户上下文、方法名){
$(“#ajax_加载_图像”).hide(“慢速”);
$(“执行页面方法”).show(“慢”);
if(result.Success==true){
警惕(“真实”);
$(“body”).css(“背景”,“#CAFFD8”);
}
否则{
$(“body”).css(“背景”,“#cafff”);
}
$(“#message”).text(“这花费了我”+结果.Time+“毫秒…”);
});
返回false;
});
});
事件背后的代码:
公共类MethodReturnedValue
{
公共整数时间{get;set;}
公共bool成功{get;set;}
}
[WebMethod(true)]
公共静态方法ReturnedValue ProperteMethodName(字符串参数)
{
随机=新随机();
MethodReturnedValue retVal=新MethodReturnedValue();
retVal.Time=random.Next(5000);
线程。睡眠(返回时间);
if(random.Next()%2==0)
{
retVal.Success=true;
}
其他的
{
retVal.Success=false;
}
返回返回;
}
同样的代码在我的asp.net应用程序中可以正常工作,但在sharepoint应用程序中不工作。
有人能帮我一下吗。对于页面方法,Web方法需要在.aspx.cs文件中 在SharePoint中(如果使用发布页面布局),在页面的cs中编写web方法 但是,如果您使用的是Web部件页面布局,那么它将不起作用