doumie7914 2018-03-21 13:02
浏览 48
已采纳

如何将不同的信息传递到基于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>
  • 写回答

1条回答 默认 最新

  • duanlu7223 2018-03-22 18:11
    关注

    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。