如何将不同的信息传递到基于ajax的单独div中,从mysql调用jquery?
Basically I am trying to pass multiple columns from a mysql data base into multiple separate divs. Below is the ajax code I am using, I am not sure if that is the only information that is needed so if you need more feel free to let me know. I got it to pull the other columns however when the Jquery/ajax combination gets called it pulls all the information into all the divs.
I added the other IDs below the console log but ultimately it just added it to the same div like stated above. Any help on this would be greatly appreciated! In the mean time ill continue my search for an answer as well.
enter code here
//jquery
var ID=$(this).val();
if (ID){
//ajax call
$.ajax({
type:'POST',
url:'GetAllData.php',
data: 'Fullname='+ID,
success: function(html)
{
console.log(html)
$('#ID').html(html);
},
});
}else{
$('#ID').html('<value="">ID NOT LOADED</select>');
}
});
PHP
$Fullname=$_POST['Fullname'];
if(!empty($_POST['Fullname']))
{
$query=$conn->query("SELECT Supervisor, Fullname, ID, BalancedScore,
IncentiveMonth FROM SomeTable WHERE ID= '".$Fullname."'order by Fullname
ASC");
$rowCount=$query->num_rows;
if($rowCount>0)
{
while($row = mysqli_fetch_array($query))
{
$a = array ("ID[]" => $row['ID'], "BalancedScore[0]" =>
$row['BalancedScore'], "Fullname[1]" => $row['Fullname']);
print_r(array_values($a));
}
}else{
echo '<option value=""> Agent Value Not Available </option>';
}
}
HTML
<select name="agent" id="agent">
<option value="">Select Agent</option>
</select>
</div>
<div class="ID_Container">
<div name="ID" id="ID" >
ID
</div>
</div>
<div name="BalancedScore" id="BalancedScore" >
Balanced Score
</div>
I actually figured it out. I made an array with my php code and encoded it.
$output = array ("IEX_ID" => $row['IEX_ID'], "BalancedScore" =>
$row['BalancedScore'], "Fullname[2]" => $row['Fullname']);
echo json_encode($output);
Then I changed my ajax to the below code and finally it adds my array to their respective divs. I used this link to help me if anyone needs help in the future. Assigning AJAX response for two separate DIV tags
$(document).on('change', "#agent", function(event) {
//jquery
var IEX_ID=$(this).val();
if (IEX_ID){
//ajax call
$.ajax({
type:'POST',
url:'GetAllData.php',
cache:false,
data: 'Fullname='+IEX_ID,
success: function(data){
var obj = JSON.parse(data);
alert(obj);
$('#IEX_ID').html(obj.IEX_ID);
$('#BalancedScore').html(obj.BalancedScore);