这是我的代码
<form method="post" role="form" id="form" enctype="multipart/form-data" autocomplete="off">
<input type="submit" id="save" name="save" value="Simpan Data Client" class="btn" style="font-size:0.7em; letter-spacing:1px; color:#666666" /> //For save
<input type="submit" id="delete" name="delete" value="Delete Client" class="btn-delete" style="font-size:0.7em; letter-spacing:1px; color:#666666; padding:8px 15px" /> //For Delete
</form>
<script type="text/javascript">
$("#form").on("submit",function (e)
{
e.preventDefault();
var formData = new FormData($(this)[0]);
$.ajax(
{
url:'Master/Database/Client/RunClient.php',
type: 'POST',
data: formData,
contentType: false,
enctype: 'multipart/form-data',
processData: false,
beforeSend:function()
{
document.getElementById("loading").style.display = "";
},
complete:function()
{
//document.getElementById("loading").style.display = "none";
},
success:function(result)
{
document.getElementById("info").innerHTML = result;
var n = result.search("error");
if(n < 0) /*document.getElementById("form").reset();*/ $(".input").val('');
}
});
});
</script>
除了输入类型submit i make之外,我可以从表单中获取所有数据。 我不能在我的RunClient.php中使用isset($ _ POST [&#34; save&#34;])和isset($ _ POST [&#34; delete&#34;])
答案 0 :(得分:1)
为提交创建单独的功能并传递&#34;提交类型&#34;取决于点击的按钮;
$('#save').click(function() {
submitForm('save');
});
$('#delete').click(function() {
submitForm('delete');
});
function submitForm(submittype) {
var formData = new FormData();
//push your form data to formData and add the submittype
formData['type'] = submittype
}
在你的php文件中
$submittype = $_POST['type']; // 'save' or 'delete'
if($submittype == 'save') {
//do save action
}
if($submittype == 'delete') {
//do delete action
}
答案 1 :(得分:0)
我用来避免按钮提交输入和更改。
<button type="button" id="save">SUBMIT</button> //For save
<script type="text/javascript">
$("#save").on("click",function (e)
{
});
</script>
因此,如果有人拒绝javscript表单将无法提交。
您可以发送如下数据:
data: {
foo: 'var'
foo2: 5
},
EDIT。对不起误解了你的问题。 只需使用javascript控制单击哪个按钮并使用隐藏字段指定值。
答案 2 :(得分:0)
'$(“#form”)。on(“submit”,function(e)'用
替换函数$(“#save”)。点击(function(){
});
$(“#delete”)。点击(function(){
});