Fix: Profile picture upload AJAX response handling
- Add dataType: 'json' to AJAX call to properly parse JSON response - Add Content-Type header to upload_profile_picture.php - Add error callback with console logging for debugging - Remove manual JSON parsing since jQuery handles it with dataType
This commit is contained in:
BIN
assets/images/pp/5f9036058b40b2c23052d8226711ac5c.png
Normal file
BIN
assets/images/pp/5f9036058b40b2c23052d8226711ac5c.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 291 KiB |
BIN
assets/images/pp/9a1f344bc68815fa15bb0a1e16017ee6.png
Normal file
BIN
assets/images/pp/9a1f344bc68815fa15bb0a1e16017ee6.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.2 MiB |
BIN
assets/images/pp/e607963d306a19d1df94c50d577ea439.jpg
Normal file
BIN
assets/images/pp/e607963d306a19d1df94c50d577ea439.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 290 KiB |
@@ -168,12 +168,8 @@ $user = $result->fetch_assoc();
|
|||||||
data: formData,
|
data: formData,
|
||||||
contentType: false,
|
contentType: false,
|
||||||
processData: false,
|
processData: false,
|
||||||
|
dataType: 'json',
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
// Parse response if needed
|
|
||||||
if (typeof response === "string") {
|
|
||||||
response = JSON.parse(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response.status === 'success') {
|
if (response.status === 'success') {
|
||||||
$('#responseMessage').html('<div class="alert alert-success">' + response.message + '</div>');
|
$('#responseMessage').html('<div class="alert alert-success">' + response.message + '</div>');
|
||||||
// Reload the current page after a short delay
|
// Reload the current page after a short delay
|
||||||
@@ -184,8 +180,10 @@ $user = $result->fetch_assoc();
|
|||||||
$('#responseMessage').html('<div class="alert alert-danger">' + response.message + '</div>');
|
$('#responseMessage').html('<div class="alert alert-danger">' + response.message + '</div>');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function() {
|
error: function(xhr, status, error) {
|
||||||
$('#responseMessage').html('<div class="alert alert-danger">Error uploading profile picture.</div>');
|
console.log('AJAX Error:', status, error);
|
||||||
|
console.log('Response Text:', xhr.responseText);
|
||||||
|
$('#responseMessage').html('<div class="alert alert-danger">Error uploading profile picture: ' + error + '</div>');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ require_once($rootPath . "/src/config/session.php");
|
|||||||
include_once($rootPath . '/src/config/connection.php');
|
include_once($rootPath . '/src/config/connection.php');
|
||||||
require_once($rootPath . "/src/config/functions.php");
|
require_once($rootPath . "/src/config/functions.php");
|
||||||
|
|
||||||
|
// Set JSON response header
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
// Check database connection
|
// Check database connection
|
||||||
if (!isset($conn) || $conn === null) {
|
if (!isset($conn) || $conn === null) {
|
||||||
die(json_encode(['status' => 'error', 'message' => 'Database connection failed']));
|
die(json_encode(['status' => 'error', 'message' => 'Database connection failed']));
|
||||||
|
|||||||
Reference in New Issue
Block a user