Jquery ajax和服务器端方法调用错误asp.net

Jquery ajax and server side method call error asp.net

本文关键字:错误 asp net 调用 方法 ajax 服务器端 Jquery      更新时间:2023-09-26

我经常使用jquery调用我的页面方法,它工作得很好。所以现在我尝试从page1调用page方法。Aspx到第二页。我在第一页。Aspx并尝试调用page2中的page方法。Aspx,这里我得到了错误。

这样我就调用了page方法——jquery代码,它是jquery的简写

function AjaxCallBack(MethodName, ObjParams, isAsync, OnSuccessHandler, OnErrorHandler) {
    try {
        //Set the callback methods for success and error
        if (OnSuccessHandler == undefined || typeof (OnSuccessHandler) == "undefined") {
            OnSuccessHandler = WebMethod_OnSuccess
        }
        if (OnErrorHandler == undefined || typeof (OnErrorHandler) == "undefined") {
            OnErrorHandler = WebMethod_OnError
        }
        //Serialize the webmethod function parameters
        var serializedParams = "";
        //using Json2.js; 
        serializedParams = JSON.stringify(ObjParams);
        alert(MethodName);
        //Make the ajax calls
        return $.ajax({
            type: "POST",
            async: isAsync,
            url: MethodName,
            data: serializedParams,
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            success: OnSuccessHandler,
            error: OnErrorHandler
        });
    }
    catch (e) {
        alert(e.Message);
    }
    return;
}
AjaxCallBack(SetSessionUrl, SessionParam, false, UpdateSession, SessionUpdateError);

像上面那样调用

所以请指导我我需要改变我的代码作为一个问题,我可以调用page2。Aspx方法从page1。aspx文件。请帮我写代码。由于

很难猜测您是如何使用上面的代码的,因为您没有显示任何特定的示例。但你也提供了页面2的路径吗?Aspx而不仅仅是它的方法名??

AjaxCallBack("page2.aspx/someWebMethod", ...)