Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ASP.NET中的jQuery未返回数据_Javascript_Jquery_Asp.net_Ajax - Fatal编程技术网

Javascript ASP.NET中的jQuery未返回数据

Javascript ASP.NET中的jQuery未返回数据,javascript,jquery,asp.net,ajax,Javascript,Jquery,Asp.net,Ajax,我是jQuery新手,已经阅读了很多教程。我的脚本无法返回数据。我有一个叫做“users.aspx”的页面。在代码隐藏页面中,我有一个名为“getUserDetails()”的方法,这并不重要,因为它从未被调用过。我的javascript通过单击td来调用,它将用户id发送到javascript函数。这部分工作正常(传入参数“userId”)。我的div改变了值,颜色也改变了,但是在AJAX块中,出现了一些问题。我想将userId值发送到代码隐藏页面中的web方法,以更新我的div内容。基于各种

我是jQuery新手,已经阅读了很多教程。我的脚本无法返回数据。我有一个叫做“users.aspx”的页面。在代码隐藏页面中,我有一个名为“getUserDetails()”的方法,这并不重要,因为它从未被调用过。我的javascript通过单击td来调用,它将用户id发送到javascript函数。这部分工作正常(传入参数“userId”)。我的div改变了值,颜色也改变了,但是在AJAX块中,出现了一些问题。我想将userId值发送到代码隐藏页面中的web方法,以更新我的div内容。基于各种教程,这看起来像是一条路要走

<script type="text/javascript">
    function loadDetails(userId) 
    {
        //Set selected menu colors       
        {
            $('td').css('backgroundColor', 'white'); //Reset all background colors to white
            $('#' + userId).css('backgroundColor', '#cccccc');
            $('#divrightcontent').html("Hi there");
        }

        //Get user details based on user id
        $.ajax({
            url: 'users.aspx/getUserDetails',
            data: { "uid": userId },
            type: "POST",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                 alert('We got the data');
                $("#divrightcontent").empty();
                $("#divrightcontent").html(data);
            },
            error: function (data, status, jqXHR) { $("#divrightcontent").html(jqXHR); }
        });
    }  
    </script>

函数加载详细信息(用户ID)
{
//设置所选菜单颜色
{
$('td').css('backgroundColor','white');//将所有背景色重置为白色
$('#'+userId).css('backgroundColor','#cccc');
$('#divrightcontent').html(“你好”);
}
//根据用户id获取用户详细信息
$.ajax({
url:'users.aspx/getUserDetails',
数据:{“uid”:userId},
类型:“POST”,
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
成功:功能(数据){
警报(“我们得到了数据”);
$(“#divrightcontent”).empty();
$(“#divrightcontent”).html(数据);
},
错误:函数(数据、状态、jqXHR){$(“#divrightcontent”).html(jqXHR)}
});
}  

我假设您已经在users.aspx的代码隐藏中创建了一个静态方法,并将其设置为[WebMethod]。您在执行AJAX调用时是否遇到任何错误?你试过调试代码吗?getUserDeails的代码可能会抛出错误而不返回任何数据。定义了
msg
的位置在哪里?请在调用ajax之前右键单击页面并运行检查工具,如果您在Net tab中遇到任何错误,请告知我们。msg不正确。我正在调试,忘了把它改回去。我编辑了这篇文章。是的,我在代码背后有一个webmethod。但是它从来没有被调用过。在PageLoad中,我执行了一个Request.Form[“uid”],但它是空的。问题不在于webmethod,而在于ajax的失败。