我如何使用Jquery Ajax调用母版页方法 [英] How I Call Master Page Method Using Jquery Ajax

查看:61
本文介绍了我如何使用Jquery Ajax调用母版页方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Jquery中有以下代码:

 function CheckSession(){
debugger;
$ .ajax({
url:'Site.Master / CheckSession',
类型:'POST',
contentType:'application / json; charset = utf-8' ,
dataType:json,
成功:函数(结果){
调试器;
if(result.d!=''){
}
},
错误:函数(错误){
alert(error.responseText);
},
async:false
});
};





i我得到的错误如下:

post http:// localhost:49669 /kaizen2g/site.master/checksession 403(禁止)



在Site.master页面的代码页面中我有这个:

 [WebMethod] 
public void CheckSession()
{
if (会话[KaizenConstants.CURRENTLOGGEDINUSER] == null
{
Response.Redirect( Login.aspx);
}
}





为什么会这样?

如何解决它?

谢谢

Harshal

解决方案

.ajax({
url:'Site .Master / CheckSession',
类型:'POST',
contentType:'application / json; charset = utf-8',
dataType:json,
成功: function(result){
debugger;
if(result.d!=''){
}
},
error:function(error){
alert(error.responseText);
},
async:false
});
};





i我得到的错误如下:

post http:// localhost:49669 /kaizen2g/site.master/checksession 403(禁止)



在Site.master页面的代码页面中我有这个:

 [WebMethod] 
public void CheckSession()
{
if (会话[KaizenConstants.CURRENTLOGGEDINUSER] == null
{
Response.Redirect( Login.aspx);
}
}





为什么会这样?

如何解决它?

谢谢

Harshal


母版页没有自己的生命。母版页的每个方法/属性都使用它与实际页面合并。它也包括WebMethod ...



Site.Master代码:

 [WebMethod] 
public static void CheckSession()
{
// ...
}



Portal.aspx标记:

 <%@     Page    语言  =  C#    MasterPageFile   =  Site.Master    CodeBehind   =  Portal.aspx.cs   继承  = 门户网站   %> ;  



您可以这样调用CheckSession:

 

.ajax({
url:' Portal.aspx / CheckSession'
类型:' POST'
...


i have the Following Code in Jquery:

function CheckSession() {
               debugger;
               $.ajax({
                   url: 'Site.Master/CheckSession',
                   type: 'POST',
                   contentType: 'application/json; charset=utf-8',
                   dataType: "json",
                   success: function (result) {
                       debugger;
                       if (result.d != '') {
                       }
                   },
                   error: function (error) {
                       alert(error.responseText);
                   },
                   async: false
               });
           };



i am getting the error as follows:
post http://localhost:49669/kaizen2g/site.master/checksession 403(forbidden)

In Code Behind Site.master page I have this:

[WebMethod]
       public void CheckSession()
       {
           if (Session[KaizenConstants.CURRENTLOGGEDINUSER] == null)
           {
               Response.Redirect("Login.aspx");
           }
       }



why is it so ??
how to solve it??
Thanks
Harshal

解决方案

.ajax({ url: 'Site.Master/CheckSession', type: 'POST', contentType: 'application/json; charset=utf-8', dataType: "json", success: function (result) { debugger; if (result.d != '') { } }, error: function (error) { alert(error.responseText); }, async: false }); };



i am getting the error as follows:
post http://localhost:49669/kaizen2g/site.master/checksession 403(forbidden)

In Code Behind Site.master page I have this:

[WebMethod]
       public void CheckSession()
       {
           if (Session[KaizenConstants.CURRENTLOGGEDINUSER] == null)
           {
               Response.Redirect("Login.aspx");
           }
       }



why is it so ??
how to solve it??
Thanks
Harshal


Master pages have no life of there own. Every method/property of a master page is merged with the real page using it. It includes WebMethod too...

Site.Master code:

[WebMethod]
public static void CheckSession()
{
  // ...
}


Portal.aspx markup:

<%@ Page Language="C#" MasterPageFile="Site.Master" CodeBehind="Portal.aspx.cs" Inherits="Portal" %>


You can call CheckSession like this:


.ajax({ url: 'Portal.aspx/CheckSession', type: 'POST', ...


这篇关于我如何使用Jquery Ajax调用母版页方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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