dousigan0499 2014-04-15 02:54
浏览 23
已采纳

回声不打印任何东西(之前是)

I am having a bit of a headache with a echo on my php code, the problem is that it isn't printing anything on screen, even though it was before, granted I added a function but when I used firebug to debug it it showed that it was getting the information out of a database correctly, just not printing it on-screen.

Where a list should be displayed there is nothing but empty space, staring into my soul.

I would appreciated if someone could point me out if I am missing something, as well why it is happening so I many not have to bother anyone anymore and if needed share my newly acquired knowledge.

PHP

function displayInfoLabs(){  

if(isset($_POST['pId'])){

    $id = $_POST['pId'];

        $info = getSpecificLabs($id);

while($row = mysql_fetch_assoc($info)){
echo '<ul>' .
        '<li>Laboratorio # ' . $row['codigolab'] . '</li>' .
        '<li>Capacidad: ' . $row['capacidad'] . '</li>' .
        '<li>Carrera: ' . $row['carrera'] . '</li>' .
        '<li>Ubicación: ' . $row['ubicacion'] . '</li>' .
     '</ul>';

   }
  }
 }


function getSpecificLabs($pId){  


 $query = "SELECT bk.idlab , bk.codigolab , bk.capacidad, bk.carrera, bk.ubicacion FROM labs as bk WHERE bk.idlab = $pId";

 $result = do_query($query);

 return $result;
}

For reference I am also including the html and JS code of this function.

JS

$("#lnkInfo").click(function() {
  var id = $('#txtId').val();


 var request = $.ajax({
  url: "includes/functionsLabs.php",
  type: "post",
  data: {

    'call': 'displayInfoLabs',
    'pId':id},

    dataType: 'json',

success: function(response){
        alert('exito')

    }
  });
});

HTML created via PHP, mind the lnkInfo which calls the JS that in turn calls the PHP

function displayList(){

 $lista = getLabs();

while($row = mysql_fetch_assoc($lista)){
echo 
      '<div class="box" id="lab'.$row['idlab'].'">
          <p id="labName">Lab #'.$row['codigolab'] . '</p>
          <p class="info"><a href="#" id="lnkInfo">Info</p></a>
          <p class="info"><a href="reservarLab.html">Reservar</p></a>
          <input type="hidden" name="txtId" id="txtId" value="'.$row['idlab'].'">
      </div>';
 }
}

Thanks a lot in advance.

EDIT:

Changing the success function made the list appear but it overrode the div's style including the buttons it had and all. This is the div's code.

div class="popUp1 hide" id="popUpCorrecto1">
        <div class="estiloPopUp">
          <span>Información de laboratorio</span>
          <span value="Cerrar" id="btnCerrar">x</span>
        </div>



          <input type = "button" value = "Eliminar" id = "btnEliminar" onclick="eliminar()" />
          <input type = "button" value = "Modificar" id = "btnModificar"  onclick="window.location='modificarLab.html';" />

        </div>  
  • 写回答

1条回答 默认 最新

  • douzhiba6873 2014-04-15 03:23
    关注

    As you said in the comments, your data is being captured, but you aren't appending it to the document. you are simply doing:

    alert('exito');
    

    What you want to do is append the response to an element that is present in your page.

    For examples sake, we can put a <div> with the id of mydata like so:

    <div id="mydata"></div>
    

    Now in your jQuery.ajax function, you could do something like the following:

    $("#lnkInfo").click(function() {
      var id = $('#txtId').val();
    
    
     var request = $.ajax({
      url: "includes/functionsLabs.php",
      type: "post",
      data: {
    
        'call': 'displayInfoLabs',
        'pId':id},
    
        dataType: 'text/html',
    
    success: function(response){
            $('#mydata').html(response);
    
        }
      });
    });
    

    As you can see in the above, we modified your success function to include

    $('#mydata').html(response);
    

    provided all your data is printed and supplied correctly, it should display on the page.

    EDIT:

    it seems in your PHP query

    $query = "SELECT bk.idlab , bk.codigolab , bk.capacidad, bk.carrera, bk.ubicacion FROM labs as bk WHERE bk.idlab = $pId";
    

    You are selecting the columns prefixed with bk.* yet trying to print out the values without the prefix as seen below:

         echo '<ul>' .
            '<li>Laboratorio # ' . $row['codigolab'] . '</li>' .
            '<li>Capacidad: ' . $row['capacidad'] . '</li>' .
            '<li>Carrera: ' . $row['carrera'] . '</li>' .
            '<li>Ubicación: ' . $row['ubicacion'] . '</li>' .
         '</ul>';
    

    Try changing the above to something like:

         echo '<ul>' .
            '<li>Laboratorio # ' . $row['bk.codigolab'] . '</li>' .
            '<li>Capacidad: ' . $row['bk.capacidad'] . '</li>' .
            '<li>Carrera: ' . $row['bk.carrera'] . '</li>' .
            '<li>Ubicación: ' . $row['bk.ubicacion'] . '</li>' .
         '</ul>';
    

    If i understood it correctly.

    Edit: ignore above php examples.

    Change the success function from:

    $('#mydata').html(response);
    

    to

    $('#mydata').append(response);
    

    As .html() replaces all content within the specified element with the supplied content.

    EDIT #2:

    From the comments, you're ajax request is run every time that #LnkInfo is triggered which seems like it happens a lot as it loads the PopUp?

    What you want to do is add in some logic, either in your jQuery function that checks if you've already appended the list to the popup and to stop it appending.

    That could be done simply by adding a boolean variable somewhere in there. Alternatively, you could just add a little div on that popup that you append it to.

    Example:

    This is your popup:

    div class="popUp1 hide" id="popUpCorrecto1">
            <div class="estiloPopUp">
              <span>Información de laboratorio</span>
              <span value="Cerrar" id="btnCerrar">x</span>
            </div>
    
            <!-- ADDED A NEW DIV HERE FOR LIST CONTENT -->
            <div id="mylistcontent"></div>
    
              <input type = "button" value = "Eliminar" id = "btnEliminar" onclick="eliminar()" />
              <input type = "button" value = "Modificar" id = "btnModificar"  onclick="window.location='modificarLab.html';" />
    
            </div>  
    

    As you can see above, I've added the following:

    <!-- ADDED A NEW DIV HERE FOR LIST CONTENT -->
                <div id="mylistcontent"></div>
    

    Now in your jQuery success function, you could append to that #mylistcontent div instead of the popup div :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧