javascript函数中的webservice返回数据表 [英] webservice return datatable in javascript function

查看:105
本文介绍了javascript函数中的webservice返回数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的问题是:如何调用在Javascript函数中返回数据表的Web服务

然后在运行时绘制此数据表.

感谢您的阅读

[以OP的名义编辑]

这是在我的代码隐藏文件中:

Hello all,

my problem is :How to call webservice that returns Data Table in Javascript function

then draw this data table in run time.

Thanks for reading



This is in my codebehind file:

public DataTable GetData(int from_month, int to_month)
{
    int year = DateTime.Now.Year;
    DataTable dt = new DataTable();
    SqlConnection con = new SqlConnection(sWebCon);
    SqlCommand com = new SqlCommand();
    com.Connection = con;
    com.CommandType = CommandType.StoredProcedure;
    com.CommandText = "usp_tbl_losses";
    SqlParameter prm_yearl = new SqlParameter("@year", SqlDbType.Int);
    prm_yearl.Value = year;
    com.Parameters.Add(prm_yearl);
    SqlParameter prm_from_monthl = new SqlParameter("@from_month", SqlDbType.Int);
    prm_from_monthl.Value = from_month;
    com.Parameters.Add(prm_from_monthl);
    SqlParameter prm_to_monthl = new SqlParameter("@to_month", SqlDbType.Int);
    prm_to_monthl.Value = to_month;
    com.Parameters.Add(prm_to_monthl);
    try
    {
        con.Open();
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = com;
        da.Fill(dt);
    }
    catch (Exception ex)
    {
        if (con.State == ConnectionState.Open)
        {
            con.Close();
        }
        dt = null;
    }
    finally
    {
        con.Close();
    }
    return dt;
}



这是我的javascript:



and this is my javascript:

<script type="text/javascript">
        var fromMonth , toMonth;
        function GetData()
        {
            fromMonth = document.getElementById('txt_from').value;
            toMonth = document.getElementById('txt_to').value;
            // I need to read returned data table below
            WebService.GetData(fromMonth, toMonth, oncomplate,onfailed);
        }

        function oncomplate() {
            alert("this worked");
        }
        function onfailed() {
            alert("error");
        }
</script>

推荐答案

嗨曼弗雷德,
您要寻找的解决方案仅在codeproject中可用
看看这个

使用JavaScript从HTML页面调用Web服务 [
HI Manfred,
The solution you are looking for is available in codeproject only
check out this

Calling Web Services from HTML Pages using JavaScript[^]

Let me know if you find any problem in implementing this.

Enjoy life :)


这篇关于javascript函数中的webservice返回数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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