Reputation: 4441
I have two ajax calls in my script. Both the AJAX calls passes the same value to two different PHP file sitting on the same folder on the localhost.
One of the AJAX request successfully passes the value to the php file. The other call passes the same value. However when I echo the value on the php script, I seemed to receive a different value. Even on inspecting the php files header I happened to see the same value that im passing. It changes inside the script. Here is my code below:
<?php
$servername = "localhost";
$username = "root";
$password = "root";
$port = "8889";
$dbname = "ImageInfo";
$checkID = isset($_POST['imageID']);
echo $checkID;
#....... code follows
?>
Both the PHP scripts has the same way way of receiving the POST request.
Here are the two AJAX calls that I make:
function loadErrorMsgs(){
$.ajax({
type: "POST",
url: "getErrorData.php",
data: ({imageID:kImageID}),
success: function(msg){
console.log(msg);
}
});
}
function loadPage(){
$.ajax({
type: "POST",
url: "getFilenames.php",
data: ({imageID:kImageID}),
success: function(filenames){
console.log(filenames);
loadProcessedImgFiles();
updateView();
}
});
}
The echo value received for getErrorData.php is always 1. However I'm not resetting the value anywhere. Any idea why is this happening?
EDIT
var kImageID = localStorage.getItem("checkID");
$(document).ready(function(){
loadErrorMsgs();
loadPage();
});
Upvotes: 0
Views: 29
Reputation: 1074
Looks like you need to change the $checkID = isset($_POST['imageID']);
code in your PHP file. Actually the value of $checkID
is true/false because you're just checking if $_POST['imageID']
has a value.
Try change your code with :
if(isset($_POST['imageID'])){
$checkID = $_POST['imageID'];
}
Also inspect your PHP file if you missed somewhere any other echo
that shouldn't be sent as a response. If you still have trouble, change all the $_POST
variable to $_GET
and call directly your php file in the browser with proper parameters like : http://localhost/getErrorData.php?imageID=test
Upvotes: 1