alex alex - 1 year ago 60
Ajax Question

Ajax image upload failure, Script doesn't get the php isset function

I've been following along with some ajax uploading tutorial and it was working properly.

Here it's how i done,
i created a form in html like this.

<form id="submit_form" action="php-script/test_lates_statusbx-script.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<label>Select Image</label>
<input type="file" name="ui-is-status_is_photo_fl" id="image_file" />
<textarea name="status_is_text_ara"></textarea>
<span class="help-block">Allowed File Type - jpg, jpeg, png, gif</span>
<input type="submit" name="is_status_forum_btn" class="btn btn-info" value="Upload" />
<div id="image_preview">

and here its my ajax code,

$('#submit_form').on('submit', function(e){
data:new FormData(this),


and my php looks like this,

echo $fileactuname = basename($_FILES['ui-is-status_is_photo_fl']['name']);
echo $textareastatus = htmlspecialchars($_POST['status_is_text_ara']);

Problem: When i click the submit buttons it doesnt execute my code. But if i echo something outside of the isset function will does.Where am i wrong ?

Answer Source

A submit button is only a successful control if it is used to submit the form.

You are:

  1. Using the submit button to submit the form
  2. Preventing the default behaviour of the submit event so the form is not submitted
  3. Collecting the data from the form with JavaScript
  4. Making an HTTP request with that data

Since (due to step 2) the submit button is no longer being used to submit the form, it isn't included in the object you create with FormData().

Test for the presence of a different piece of data that you are sending.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download