antHak antHak - 9 months ago 31
Ajax Question

I'm sending an Ajax request but I'm getting no response from my .php file?

I just want to state that Ajax and JQuery are really vague in my head so I'm still learning. However, I understand a little the idea behind just not the functionalities in details.

My example here is that I have this input type file :

<input id="photo" type="file" capture="camera" accept="image/*">

And I'm trying to simply send the file through Ajax request. Here's my code:

$(document).ready(function() {
$("#photo").change(function() {
var file = $("#photo").prop('files')[0];
var data = new FormData();
data.append(, file);
type: 'POST',
url: 'php.php',
processData: false,
contentType: false,
data: data,
success: function() {
alert("It was a success");
error: function(jqXHR, textStatus, errorThrown) {


Everything seems to work, the Ajax's response status return 200 but I don't feel like it's interacting with my php.

Here's my php:

echo $_FILES['file']['type'];
echo "COME ON WORK";

Is it possible that it has something to do with Same Origin Policy? I looked around and found similar questions related to it.


If you are referring to the echos, you need to put resp in your success

   success: function(resp) {
                alert("It was a success");
                alert("PHP echos:" + resp);