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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度