没有使用ajax在帖子中获取Formdata

时间:2016-10-17 06:25:58

标签: javascript php ajax

我正在尝试将formdata添加到我的php文件中。但我对帖子没有任何价值。请告诉我我在做什么是对的?我在帖子中做错了什么

// add item to additem
<script type="text/javascript">
$(document).ready(function(){
$("#additembutton").click(function(evt){
    evt.preventDefault();
    var formData = new FormData($("form #itemform")[0]);
    alert(formData);
    $.ajax({
        url: 'additem.php',
        type: 'POST',
        data: formData,
        async: false,
        cache: false,
        contentType: false,
        enctype: 'multipart/form-data',
        processData: false,
        success: function (response) {
            alert(response);
        }
    });
        return false;
});
    </script>

// form submit image

这是我的additem.php文件

<?php
include '../class/dbconfig.php';
$filename=$_POST['myfile']['name'];
echo $_POST['myfile'];

这是我的html表单

 <form class="form-horizontal"  enctype="multipart/form-data">
 <div class="form-group">
 <label for="select" class="col-md-3 control-label">Menu Type</label>
 <div class="col-md-6">
 <select class="form-control" id="menutype">
 <option>Select Menu</option>
 <option value="fastfood">FastFood</option>
 <option value="other">Other</option>
 </select>
 </div>
 </div>
 <!--
 <div class="form-group" id="otherdiv">
 <label for="menuorder" class="col-md-3 control-label">Other Menu Type</label>
 <div class="col-md-6">
 <input type="number" class="form-control" id="othermenu"  placeholder="Enter Order">
 </div>
 </div>
 -->
 <div class="form-group">
 <label for="menuorder" class="col-md-3 control-label">Menu Order</label>
 <div class="col-md-6">
 <input type="number" class="form-control" id="menuorder" pattern="[0-9]+" placeholder="Enter Order">
 </div>
 </div>
 <div class="form-group">
 <label for="select" class="col-md-3 control-label">Menu Status</label>
 <div class="col-md-6">
 <select class="form-control" id="menustatus">
 <option value="1">Active</option>
 <option value="0">Deactive</option>
 </select>
 </div>
 </div>
 <div class="form-group">
 <div class="col-md-6 col-md-offset-3">
 <button type="reset" class="btn btn-default">Cancel</button>
 <button type="button" class="btn btn-primary" id="addmenubutton" >Submit</button>
 </div>
 </div>
 </form>

1 个答案:

答案 0 :(得分:1)

您只需要通过邮件发送表单:

<form method="POST">