3

ajax呼び出し後にjqueryでユーザー定義関数を呼び出そうとしていますが、

呼び出す必要がある関数: downloadCurrentKey()

私の要件は、「generate_billing_key」をクリックした後、関数 downloadCurrentKey() が自動的に呼び出され、ラベルをクリックするとその時点で関数も呼び出されることです。

google chrome では問題なく動作しますが、Mozilla Firefox では動作しません。

以下はjsコードです。ガイドしてください。

    $(document).on('click', '#generate_billing_key', function(){
    var url = $('#hdGenerateBillingKeyPair').val();


    $.post(url, {


    }, function (data) {

        var obj = JSON.parse(data);
        content="<label id='btn_download_billing_key'>
                      Click here to download key</label>";;

        $("#newKeyDiv").html(content);
        downloadCurrentKey();
    });
});


$(document).on('click', '#btn_download_billing_key', function(){
    downloadCurrentKey();
});

function downloadCurrentKey(){
    var url=$('#hdDownloadBillingKeyPath').val();
        my_form=document.createElement('FORM');
        my_form.name='myForm';
        my_form.method='POST';
        my_form.action=url;
        my_form.submit();
}

URLのコードは以下の通り

/**
 * @Route("/downloadBillingKey",name="download_billing_key")
 * @Template()
 */
public function downloadBillingKeyAction(Request $request) {
    $file_name="key";
    $file_content="";

    header("Content-type: plain/text");
    header("Content-Disposition: attachment; filename=$file_name.txt");
    header("Pragma: no-cache");
    header("Expires: 0");
    echo $file_content;
    die;
}

ありがとうございました。

4

2 に答える 2