Thursday, August 1, 2019

php - How to have two buttons in a same form to do different actions in ajax?



I have a form, which take name from form and it sends to javascript codes and show in php by Ajax. these actions are done with clicking by submit button, I need to have another button, as review in my main page. how can I address to ajax that in process.php page have "if isset(submit)" or "if isset(review)"?
I need to do different sql action when each of buttons are clicked.
how can I add another button and be able to do different action on php part in process.php page?

















process.php:




print "
Your name is ".$_POST['name']." ";

?>

Answer



You just need to add a button and an onclick handler for it.



Html:



 



Js:



$("#review").click(function(){
var myData = $("#myform").serialize() + "&review=review";
$.post('process.php', myData , function(data) {
$('#results').html(data);
});
}
);



Since you have set a variable review here, you can use it to know that is call has come by clicking the review button.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...