Gino Gino - 3 months ago 9
Javascript Question

How can I send a response from a Jquery modal form to a php function?

I am using the basic modal confirmation example but when I user clicks on the Approvebutton, I want it to execute the php function Approve();

<script>
$( function() {
$( "#dialog-confirm" ).dialog({
resizable: false,
height: "auto",
width: 400,
modal: true,
buttons: {
"Approve": function() {
$( this ).dialog( "close" );
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
} );
</script>



echo "<a href='test.php?cmd_test=approve_ts&test_id=$test_id'>Approve</a>";

if (isset($_GET["cmd_test"]))
{
$test_id = $_GET['test_id'];
//do other stuff
}

Answer

Create a PHP script. I'll call it ajax.php. In that, put your PHP code.

<?php
if (isset($_GET["cmd_test"]))
{
    $test_id = $_GET['test_id'];    
    //do other stuff
}
?>

Then, as others have said, use an AJAX request.

$.get('ajax.php', function (data) {
    // do stuff here
});

Put that in your Approve/Cancel functions

Comments