提交完成后调用函数

时间:2018-02-07 09:40:35

标签: jquery

我想在提交完成后调用一个函数。提交在新标签中打开pdf。

$(form).submit() // fire the submit 

但是当我尝试这个approch时

$(form).submit(function(e){            
        callfunction();
    }
);

提交不会触发。

这是我的代码。

<form id="form" action="#" method="post" target="_blank">
        <input type="hidden" name="docId">            
</form>

function getSubmitAttribute(data) {
    $form = $("#form");
    $(form).find("input[name=docId]").val($(data).parent().attr('id'));
    return form;
}

$('#datable tbody').on('click', '.cell', function () {
    form = getSubmitAttribute($(this));
    $(form).attr('action', url);
    $(form).submit();
}

谢谢。

1 个答案:

答案 0 :(得分:0)

我在项目中完成此操作的方法是让包含PDF的响应设置为cookie(因为我不能让它运行代码,它不是网页)。然后我可以在发送表单的页面中查询cookie。在伪代码中:

Public Class Form1
    Dim area As Integer
    Dim Length As Decimal
    Dim Width As Decimal
    Dim Depth As Decimal
    Dim CostNo As Integer
    Dim CostNa As String
    Dim combo As String
    Dim ErrorFlag As String

    Private Sub Area2_Click(sender As Object, e As EventArgs) Handles Area2.Click
        Length = txtLength.Text
        Width = txtWidth.Text
        Depth = txtDepth.Text

        ErrorFlag = ErrorLook(Length, Width, Depth)
        If ErrorFlag = "True" Then
            MsgBox("Invalid")
        ElseIf ErrorFlag = "False" Then
            MsgBox("u Good")
        End If

        'getting input from the costumer number text box
        'CostNo = CostumerNo.Text
        'getting input from the costumer name text box
        'CostNa = CostumerName.Text
        'store the names together as a new variable
        'combo = CostNo & " " & CostNa

        'displays the full name in the third text box
        Result.Text = combo & " " & "Area " & a(Width, Length)
    End Sub
    'sets the boundaries for the input values
    Public Function ErrorLook(ByVal w As Decimal, ByVal l As Decimal, ByVal d As Decimal) As String
        Dim FlagError As String
        FlagError = "False"
        If txtLength.Text < 1 Or txtLength.Text > 10 Then ErrorFlag = "True"
        If txtWidth.Text < 1 Or txtWidth.Text > 10 Then ErrorFlag = "True"
        If txtDepth.Text < 1 Or txtDepth.Text > 2 Then ErrorFlag = "True"
        Return FlagError
    End Function
    'calculates the area
    Public Function a(ByVal w As Decimal, ByVal l As Decimal) As String
        Dim area2 As Decimal
        area2 = Width * Length
        Return area2
    End Function
    'calculates the width
    Public Function L(ByVal W As Decimal) As Decimal
        Width = txtWidth.Text + (2 * txtDepth.Text)
        Return Width
    End Function
    'calculates the length
    Public Function W(ByVal L As Decimal) As Decimal
        Length = txtLength.Text + (2 * txtDepth.Text)
        Return Length
    End Function
    'displays the date and time of the system it is eing run from
    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        lbTime.Text = Now()
    End Sub

    'the clear button for clearing all of the fields
    Private Sub CA_Click(sender As Object, e As EventArgs) Handles CA.Click
        Reset()
        txtDepth.Text = ""
        txtLength.Text = ""
        txtWidth.Text = ""
        CostumerName.Text = ""
        CostumerNo.Text = ""
        Result.Text = ""
        output.Text = ""
    End Sub
End Class

我使用表单发送cookie名称和值,确保它们(很可能是)唯一,这样如果在多个窗口中发生这种情况,代码就不会混淆

相关问题