我有一个包含4个字段的表单,一个是文件上传 在添加文件上传之前,它工作正常 但是当我添加文件字段并且更改了ajax函数时,没有任何效果 我在php页面中发布了print_r,它没有被打印 我的代码如下
$(function() {
validateNotifica();
});
function validateNotifica() {
desc = $("#notificaMsg").val();
title = $("#notificaTitle").val();
errorText = $("#error-text");
if (desc === '' || title === '') {
errorText.innerHTML = "* All fields are required.";
errorText.addClass("red");
errorText.show();
return;
}
errorText.hide();
errorText.removeClass("red");
errorText.removeClass("green");
$.ajax({
dataType: 'json',
type: 'POST',
url: 'calendar/admin/php/notifica_events.php',
data: {
action: 'post',
title: title,
message: desc
},
success: function() {
sendPushNotification(desc, title, function() {
errorText.html("Notifica inviata con successo.");
errorText.addClass("green");
errorText.show();
$('.other-quotes').empty();
loadNotifications();
});
},
error: function(data) {
errorText.innerHTML = "* " + data.responseText;
errorText.addClass("red");
errorText.show();
}
});
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form class="form-horizontal" id="notificaEvent" action="" method="post">
<div class="form-group">
<label class='col-sm-3 control-label' for='notificaTitle'>Titolo</label>
<div class='col-sm-7'>
<input id='notificaTitle' class='form-control' maxlength="50" placeholder='' />
</div>
</div>
<div class="form-group">
<label class='col-sm-3 control-label' for='Type'>Type</label>
<div class='col-sm-7'>
<input type="radio" id="notificaType" name="type" value="important" checked="checked">Important
<input type="radio" id="notificaType" name="type" value="notimportant"> Not Important<br>
</div>
</div>
<div class="form-group">
<label class='col-sm-3 control-label' id="notificaAttachment" for='Attachment'>Attachment</label>
<div class='col-sm-7'>
<input type="file" name="notificaFile" id="notificaFile">
</div>
</div>
<div class="form-group">
<label class='col-sm-3 control-label' for='notificaMsg'>Messaggio</label>
<div class='col-sm-7'>
<textarea id='notificaMsg' class='form-control' maxlength="300" placeholder=''></textarea>
</div>
</div>
<div id="error-text" class="error-text form-group no-margin-side" style="display: none;">
<span>* Tutti i campi sono obbligatori</span>
</div>
<div class="footer text-center">
<input type='button' id='notifica_submit' class='btn btn-success send' data-loading-text='Sending notification...' value="INVIA" />
</div>
</form>
我想将notificaFile传递到php页面,但是当我更改代码时不起作用