still fairly new to AJAX. I feel I'm not grasping it completely. I want to submit partial data to the server, perform an SQL query and return the results. This is what I have so far:
jQuery
j$('select[name=agent_Name]').change(function(event) {
event.preventDefault();
var agentID = j$(this).val();
post_data = {'agent_ID':agentID};
console.log("About to post data to the server");
j$.post('../include/booking_Modify.php', post_data, function(response){
if(response.type == 'AgDEpCd'){
output = response.text;
console.log(output);
}
if(response.type == 'error'){
output = response.text;
console.log(output);
}
}, 'json');
});
PHP
<?php
session_start();
require("../include/conn.php");
dbopen();
//check $_POST vars are set, exit if any missing
if(!isset($_POST["agent_ID"]))
{
$output = json_encode(array('type'=>'error', 'text' => 'Nothing was selected!'));
die($output);
}
$stmt = $conn->prepare("SELECT AgDEpCd FROM AGENTS WHERE AgentID = ?");
$stmt->bind_param('i', $_POST["agent_ID"]); // bind variables to the parameter
$stmt->execute();
$row = $result->fetch_assoc();
$AgDEpCd = $row['AgDEpCd'];
$stmt->close();
$output = json_encode(array('type'=>'AgDEpCd', 'text' => $AgDEpCd));
die($output);
?>
I checked to make sure: the file path was correct. var agentID = j$(this).val(); actually grabs a value, which it does Manually entered the SQL query into PHPMyAdmin to ensure I was retrieving results. I can't seem to return anything from the server. I'm not sure this is even possible. Please help!