Skip to content Skip to sidebar Skip to footer

Jquery Ajax Post Save Delete Submit

Here is my code
).click(function() { submitForm('save'); }); $('#delete').click(function() { submitForm('delete'); }); functionsubmitForm(submittype) { var formData = newFormData(); //push your form data to formData and add the submittype formData['type'] = submittype }

in your php file

$submittype = $_POST['type']; //'save'or'delete'if($submittype == 'save') {
 //do save action
}
if($submittype == 'delete') {
 //do delete action
}

Solution 2:

I use to avoid submit inputs and change by buttons.

<buttontype="button"id="save">SUBMIT</button> //For save

<scripttype="text/javascript">
$("#save").on("click",function (e)
{

});
</script>

So, if anyone deativates javscript form will not submit.

And you can send the data like this:

data: {
    foo: 'var'
    foo2: 5
}, 

EDIT. Sorry missunderstood your question. Just control with javascript what button is clicked and assign a value with a hidden field.

Solution 3:

'$("#form").on("submit",function (e)' replace the function with

$("#save").click(function() {

});

$("#delete").click(function() {

});

Post a Comment for "Jquery Ajax Post Save Delete Submit"