Tag: pagemethods

PageMethods,jQuery和JSON

我试图像这样使用jQuery调用PageMethod : [WebMethod] public stataic string WebMethod(PostData data) { //DO WORK return “a”; } PostData类如下: public class PostData { public string Guid{get;set;} public string Action{get;set;} public string Id{get;set;} } 我正在从jQuery调用方法,如下所示: $.ajax({ type=”POST”, url: ‘url’, data: JSON.stringify(b), contentType: “application/json;charset=utf-8”, dataType: “json”, success: function (msg) { var t = $(c).html(); $(c).html(t + “” + $.evalJSON(msg.d)); }, error: […]

jquery PageMethod说该方法不存在

我想获得这个asp.net函数的值: [ScriptMethod, WebMethod] public static bool checkRefresh() { return isChanging; } 通过使用PageMethod在jquery中调用它: var isAllowed = false; $(“#edit”).click(function () { PageMethods.editFunc(); PageMethods.checkRefresh(DisplayMyResult); //this line gives the error, though it’s probably because it’s first. }); function DisplayMyResult(ResultString) { isAllowed = ResultString; if (isAllowed == true || isAllowed == “true”) { location.reload(); } else { PageMethods.checkRefresh(DisplayMyResult); } } […]

ASP.NET AJAX PageMethods调用.NET 4.5 IIS 7.5的整个页面

我在aspx页面的代码隐藏中调用pageMethod。 我得到整个页面的响应而不是webMethod响应。 此外,我尝试使用jquery调用相同的webMethod并将整个页面作为响应。 Client: function TestNumber() { PageMethods.getNumber(ResponseTest); } function ResponseTest(response){ var num = response.d; } CodeBehind: [WebMethod] public static int getNumber() { return accountNumber; } 我正在使用.NET 4.5.1和IIS7.5,我认为问题是在VS2013中构建的无扩展URL中实现的。 我使用以下web.config sys.webserver 我通过Jquery ajax调用尝试了相同的操作并获得了整页。 我错过了什么吗?

字符串超过maxJsonLength且小于250kb

我正在使用一个实体和ajax。 我希望在使用JavaScript创建的网格中使用entity framework提供完整的表格。 我目前发送的表格少于140行。 我的代码工作,如果我在表中只有50行,我得到以下错误: {“Message”:”Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.”,”StackTrace”:” at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj)\r\n at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)”,”ExceptionType”:”System.InvalidOperationException”} 在我的网络统计数据中,我的响应正文中的XMLHttpRequest出现500错误,我有错误,如上所示。 […]

页面方法从jQuery调用到Sharepoint

我在MS SharePoint 2010的_LAYOUTS文件夹中部署了一个应用程序页面(aspx)。 我想在使用jQuery标记[WebMethod]属性的页面内调用一个方法。 我在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) { […] } }); }); 遗憾的是,此代码不起作用。 问题在于URL:事实上,如果我使用这样的绝对URL,它就可以工作 var theUrl = ‘http://server/sites/xxx/_layouts/MyProject/MyPage.aspx/MyMethod’; 我怎样才能以绝对的方式改变我的道路?

window.location更改失败AJAX调用

我有一个点击跟踪AJAXfunction(在.aspx页面上调用WebMethod ),我需要在用户点击链接时调用它。 不幸的是,我正在使用window.location = “newUrl”来更改页面,这似乎使AJAX调用失败。 有没有解决的办法? 我不需要从AJAX调用中获取任何信息,我只需要确保调用WebMethod 。 我知道我可以重定向success()或failure()调用,但是我必须等待clickTracking()方法运行,这需要~ 1s 。 这是项目规范中的协议所不能接受的,因此不是一个可行的解决方案。

使用jquery调用ascx页面方法

我知道我可以使用以下语法使用jquery调用页面方法 $.ajax({ type: “POST”, url: “Default.aspx/GetDate”, data: “{}”, contentType: “application/json; charset=utf-8”, dataType: “json”, success: function(msg) { // Replace the div’s content with the page method’s return. $(“#Result”).text(msg.d); } }); 这适用于aspx页面但是可以使用ascx页面吗? (网页控制) 我已经尝试了大约半个小时,因为我无法让它工作,我想知道它是否可能。 注意:为了清楚,当我尝试调用ascx页面时,我正在更新jquery中的url 🙂