I'm trying to evaluate what PHP information to display depending on when a user selects that item from a list. After help and some research, I've heard a lot about AJAX and have looked into it, however, I'm a bit confused on the use of it.
I have an AJAX function to return to me a variable value from an external PHP file and it's working as anticipated. However, I would really like to capture that and set it to a PHP variable to continue my script execution. How does one accomplish this? I want to stay within the same file as the one that called the AJAX function. I don't think I fully comprehend how it all works and I'm still unsure of the exact method to get that value as a variable in my current PHP file.
My AJAX:
function captureName(item){
$.ajax({
type: 'POST',
url: 'externalFile.php',
data: { item: item },
success: function(data) {
alert(data);
}
});
}
My PHP External File:
$item = $_POST['item'];
echo $item;
Stuff I want to set on my current PHP File determined by what is returned by AJAX:
switch ($item){
case "item1":
$itemName = "item1";
$location = "location";
$HWType = "HW Type";
break;
case "item2":
$vmName = "item2";
$location = "location2";
$HWType = "HW Type2";
break;
}