I'm having a problem with ajax call. I want to pass information on the server side but always when I call ajax request it ends with error. Weird is, that I used exactly the same code, same lines, in previous project.
This is my ajax request (php_session_id is not undefined, I'm checking that every time):
$.ajax({
data: { unique: php_session_id },
url: 'server/uploading_files.php',
method: 'POST',
success: function (response) {
console.log("response");
},
error: function() {
console.log("some error");
}
});
And this is my uploading_files.php file:
header('Content-Type: application/json');
session_start();
if( isset( $_POST['unique'] ) ) {$_SESSION['unique_id'] = $_POST['unique'];}
$path_to_save = 'upload/' . $_SESSION['unique_id'] . '/';
if( !is_dir( $path_to_save ) ) {
if ( !mkdir( $path_to_save, 0777, true ) ) {
die('Failed to create folder for uploaded photos...');
}
}
Error codes when I use
error: function(jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
}
are:
jqXHR - Object {readyState: 4, responseText: "Failed to create folder for uploaded photos...", status: 200, statusText: "OK"}
textStatus - parsererror
errorThrown - SyntaxError: Unexpected token F(…)
Don't you have any idea how to solve it, please?
答案 0 :(得分:1)
I think it's because your PHP return's nothing. Try to setup echo "something here"
and look how is it going.
Go to network tab in chrome console and check what code is returned by your request.