如何从ajax调用代码隐藏方法 [英] How do I call code behind method from ajax

查看:74
本文介绍了如何从ajax调用代码隐藏方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 -



一开始保持简单,但不能让它起作用。我正在尝试使用ajax调用代码隐藏方法。但我回来的错误不是描述性的,也不确定我做错了什么。跟着一些不同的文章,似乎我让它变得比它应该更难。下面是代码:



这是错误:{消息:身份验证失败。,StackTrace:null,ExceptionType:系统.InvalidOperationException}



Ajax

Hi -

Keeping it simple at first to start out with but not getting it to work. I'm trying to call code behind method using ajax. But my error that it is returning isnt descriptive and not sure what I'm doing wrong. Followed a few different articles and seems like I'm making it more difficult than it should be. Here is the code:

Here is the error : "{"Message":"Authentication failed.","StackTrace":null,"ExceptionType":"System.InvalidOperationException"}"

Ajax

 $(document).ready(function () {
    $.ajax({
        url: "Registration.aspx/GetData",
        type:"POST",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
            $('#responseContent').text(data.d);
        }

    });
});





这是背后的代码:



Here is the code behind:

[WebMethod]
public static string GetData()
{
    return "Code behind string";
}

推荐答案

(document).ready(function(){
(document).ready(function () {


.ajax({
url:Registration.aspx / GetData,
类型:POST,
contentType:application / json; charset = utf-8,
dataType:json,
成功:函数(数据){
.ajax({ url: "Registration.aspx/GetData", type:"POST", contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) {


('#responseContent')。text(data.d);
}

});
});
('#responseContent').text(data.d); } }); });





这是背后的代码:



Here is the code behind:

[WebMethod]
public static string GetData()
{
    return "Code behind string";
}


这篇关于如何从ajax调用代码隐藏方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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