ajax代码不接受文件发送

时间:2016-01-26 10:14:58

标签: php jquery html ajax

我有简单的sendemail.php表单。我想添加文件发送(文件将添加到ftp)。这是我的表格:

<div class="status alert alert-success" style="display: none"></div>
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php" enctype="multipart/form-data">
    <input type="text" placeholder="Vardas Pavarde" name="vp" id="contact-form-name" value="" style="color: #9F9F9F; font: 13px Arial; float: left; width: 180px; border: none; background: none; border: solid 1px #343434;"/><br/>
    <textarea name="zinute" rows="3" cols="40" style="color: #9F9F9F; font: 13px Arial; float: left; width: 180px; border: none; background: none; border: solid 1px #343434;"></textarea><br/>
    <input type="file" id="foto" required="required" name="foto" style="color: #9F9F9F; font: 13px Arial; float: left; width: 180px; border: none; background: none; border: solid 1px #343434;"><br/>
    <input type="submit" class="button" id="contact-form-send" value="Siusti" style="color: #9F9F9F; font: 13px Arial; float: left; width: 180px; border: none; background: none; border: solid 1px #343434;" />
</form>

这是我的sendemail.php:

<?php
    header('Content-type: application/json');
    $status = array(
        'type'=>'success',
        'message'=>'Thank you for contact us. As early as possible  we will contact you '
    );
    $vp = @trim(stripslashes($_POST['vp'])); 
    $zinute = @trim(stripslashes($_POST['zinute'])); 

    move_uploaded_file($_FILES['foto']['tmp_name'], 'image/' . $_FILES['foto']['name']);

    $success = @seet($vp, zinte);

    echo json_encode($status);
    die;

我认为问题出现在jQuery AJAX代码中,但我还没有研究过这种语言,所以请帮忙。谢谢大家!

jQuery的:

var form = $('#main-contact-form');
form.submit(function(event){
    event.preventDefault();
    var form_status = $('<div class="form_status"></div>');
    $.ajax({
        url: $(this).attr('action'),
        beforeSend: function(){
            form.prepend( form_status.html('<p><i class="fa fa-spinner fa-spin"></i> Email is sending...</p>').fadeIn() );
        }
    }).done(function(data){
        form_status.html('<p class="text-success">' + data.message + '</p>').delay(3000).fadeOut();
    });
});

0 个答案:

没有答案