通过AJAX将数据和图像发送到PHP

时间:2018-03-31 05:47:20

标签: php jquery ajax

我正在尝试将我的数据与图像一起传递给php,但它抛出错误undefined index我的代码如下

HTML

<form class="form-horizontal" name="event" id="event" enctype="multipart/form-data">
 <input type="text" name="txtEName" id="txtEName" required/>
 <input type="text" name="txtEFree" required placeholder="(in minutes)"/>
 <input type="text" name="txtEFirstPay" required/>
 <input type="text" name="txtEFirstDuration" placeholder="(in minutes)"/>
 <input type="file" name="files[]" multiple/> 
 <button type="button" id="saveEvent">SAVE</button>
</form

AJAX

 $("#saveEvent").on('click',(function() {
      var formData = new FormData($("#event"));
      $.ajax({
        url: "saveEvent.php", 
        type: 'POST',
        data: formData, 
        contentType: false,
        cache: false
        processData:false,
        success: function(data)
        {
          //further...
        }
      });
     }));

PHP

<?php
  require_once ("Php/db_connect.php");
  $name=$_REQUEST['txtEName'];
  echo var_dump($name);
  $free=$_REQUEST['txtEFree'];
  fpay=$_REQUEST['TxtEFirstPay'];
  $fduration=$_REQUEST['txtEFirstDuration'];
  $filename=$_FILES['filename']['name'];
  //upload code follows...
 ?>

当我尝试echo $name显示错误时

  

注意:未定义的索引:txtEName

这有什么问题。  请帮助..

0 个答案:

没有答案