在ASP.NET应用程序中通过jQuery提交表单

时间:2018-08-09 02:00:27

标签: javascript c# jquery asp.net html5

我有一个文件和表单,称为:

File: output.aspx
<form action="output.aspx?d=png" method="post" id="download-chart-form">
    <input type="hidden" id="download-chart-dataUrl" name="dataUrl" />
</form>

然后在该文件中,我就这样拥有Javascript / jQuery:

File output.aspx
// also have this but still not working
 $(document).ready(function ()
{
    $(function ()
    {
        var oldPostBack = __doPostBack;
        __doPostBack = function ()
        {
            $("form").triggerHandler("submit");
            oldPostBack.apply(this, arguments);
        };
    });

    ...

            var img = new Image();

            img.onload = function ()
            {
                ctxt.drawImage(this, 0, 0);
                domURL.revokeObjectURL(url);
                var dataUrl = d3Canvas.toDataURL();
                $('#download-chart-dataUrl').val(dataUrl);
                var downloadExcelForm = $('#download-chart-form');
                downloadExcelForm.submit();
            };

            img.src = url;

我收到了带有警报的javascript,告诉他们dataUrl和所有对象均已创建,但无法将表单发送回output.aspx.cs。

后面的代码是:

public partial class output : PageBase
{
    protected override void Page_Load(object sender, EventArgs e) 
    {
        base.Page_Load(sender, e);

        if (!IsPostBack)
        {
            string png = Request["d"] ?? string.Empty;

            if (string.IsNullOrEmpty(d))
            {
             ...

0 个答案:

没有答案