3

I have two different pages that serve separate functions.

When a button is clicked, data is posted to the database through finalizecontract.php. contract.php is a TCPDF form that uses the data from the database to fill out and generate the signed version of the contract, and saves the PDF file to a folder on my server.

I already tested and verified that the output works properly. I'm trying to figure out how to run contract.php when the Finalize Contract button is clicked. I attempted to use $.get but it's not working (or I have it in the wrong place).

What is the proper method of posting the data to the database, then calling the TCPDF file to save the contract in a PDF form?

<script type="text/javascript">

     function finalizecontract() {
        // Add record
        $.post("ajax/finalizecontract.php", {
            uuid: $("#c_uid").val(),    
        }, function (data, status) {
            if(data != "Success")
            {
                alert(data);
                $.get('contract.php');
            }
            else
            {
                $("#finalize_contract_modal").modal("hide");

                location.reload(true);
            }
        });
    }
</script>

1 Answer 1

2

I think you may want to use the .done() chain on $.post()

$.post("ajax/finalizecontract.php", {
    uuid: $("#c_uid").val(),
}).done(function (data) {
    //I would `console.log(data)` here to confirm you are getting the expected values
    if(data != "Success") {
        alert(data);
        $.get('contract.php');
    } else {
        $("#finalize_contract_modal").modal("hide");
        location.reload(true);
    }
);

Docs (See final example) https://api.jquery.com/jquery.post/

Sign up to request clarification or add additional context in comments.

6 Comments

It's still not running the contract.php file. The data is being posted to the database through finalizecontract.php, but contract.php isn't running because the PDF isn't being saved. I just confirmed again that contract.php works when I run it on it's own.
What is data printing out as? Additionally you could add ajax/finalizecontract.php for more context.
It moved pretty quick because of the reload, but it said Success
I just realized my stupid error... let me try it and see if it works. / edit: Yep... had it under the fail section, not the actual successful section. And now I look dumb, with which I certainly don't need any extra assistance. Thanks for your help!
You can set your console to persist so it doesn't clear on reloads. stackoverflow.com/questions/5327955/…
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.