php - Issue in ajax function with file data

307

i have a form with 4 fields, one is file upload before adding file upload it was working fine but when i added file field and ajax function changed, nothing is working i print_r post in php page, its not getting printed my code is as follows

$(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 id="notificaEvent" action="" method="post">
 <div >
  <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 >
  <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 >
  <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 >
  <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" >
  <span>* Tutti i campi sono obbligatori</span>
 </div>
 <div >
  <input type='button' id='notifica_submit' class='btn btn-success send' data-loading-text='Sending notification...' value="INVIA" />
 </div>
</form>



People are also looking for solutions of the problem: gd library extension not available with this php installation.
Source

Share


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.


Similar questions

Find the answer in similar questions on our website.

586 php - Issue in ajax function with file data
499 javascript - WP wp_ajax_function is not calling PHP function
766 php - configureListFields issue when I try to update a data with editable option
184 php - Calling the function inside helper file
160 php - Nginx "No such file or directory error" for existing file path with appropriate permissions
652 php - How to search 'Child' data with multiple records in Datatable?
186 check if the file is audio file in PHP
37 request.files is empty from php curl request
236 php - How to retrieve and display relationship data in Laravel?
741 php - User id won't save to database getting null

People are also looking for solutions to the problem: php - Laravel validation rule for domain name

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.