Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.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
从asp.net代码中调用jquery函数_Asp.net - Fatal编程技术网

从asp.net代码中调用jquery函数

从asp.net代码中调用jquery函数,asp.net,Asp.net,我需要在引导中创建饼图。。在谷歌搜索中,我得到了一段代码。。 如何从asp.net codebehind调用此函数?如何将数据库中的数据提供给piechart $.plot('#placeholder', data, { series: { pie: { show: true } } }); 试一试 受保护的void myButton(对象发送方,事件参数e) { ScriptManager.RegisterStartup

我需要在引导中创建饼图。。在谷歌搜索中,我得到了一段代码。。 如何从asp.net codebehind调用此函数?如何将数据库中的数据提供给piechart

$.plot('#placeholder', data, {
    series: {
        pie: {
            show: true
        }
    }
});
试一试

受保护的void myButton(对象发送方,事件参数e)
{
ScriptManager.RegisterStartupScript(this.Page,this.GetType(),“tmp”,
“占位符(参数…)”,false);
}

我建议相反,让jQuery代码通过ASP.NET AJAX页面方法调用服务器端,如下所示:

$(document).ready(function() {
    // For example's sake, this will ask the database for 
    // data upon the DOM being loaded
    $.ajax({
        type: "POST",
        url: "PageName.aspx/GetPieChartData",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(result) {
            // Plot result data returned from AJAX call to server
            $.plot('#placeholder', result.d, {
                series: {
                    pie: {
                        show: true
                    }
                }
            });
        }
    });
});

注意:您需要将
PageName.aspx
重命名为实际的.aspx页面名称


代码隐藏:

[WebMethod]
public static string GetPieChartData()
{
    // Go to database and retrieve pie chart data
    string data = GetPieChartDataFromDatabase();

    return data;
}

注意:ASP.NET AJAX页面方法会自动对返回的数据进行JSON编码,因此不需要在服务器端进行序列化调用。另外,请注意ASP.NET AJAX页面方法必须是静态的,因为它们与实际页面类本身没有交互

[WebMethod]
public static string GetPieChartData()
{
    // Go to database and retrieve pie chart data
    string data = GetPieChartDataFromDatabase();

    return data;
}