Javascript 运行PHP脚本的AJAX(jquery)不起作用

Javascript 运行PHP脚本的AJAX(jquery)不起作用,javascript,php,jquery,mysql,ajax,Javascript,Php,Jquery,Mysql,Ajax,我试图对从目录输出图像的php脚本进行ajax调用 我将此作为我的php脚本: <?php $con = @mysqli_connect('myhost','myusername','myuserpass','myuserDB') or die('Could not connect to the database.'." ". __FILE__ ." ". __LINE__); $photoFile = mysqli_query($con, 'select photoFile fr

我试图对从目录输出图像的php脚本进行ajax调用

我将此作为我的php脚本:

<?php

 $con = @mysqli_connect('myhost','myusername','myuserpass','myuserDB') or die('Could not connect to the database.'." ". __FILE__ ." ". __LINE__);

 $photoFile = mysqli_query($con, 'select photoFile from photoInfo');
  while ($p = mysqli_fetch_array($photoFile)){
    echo '<img class="image" src='."../img/".$p['photoFile'].".jpeg />";
  };
 mysqli_close($con);

?>
我到底做错了什么?当我自己运行php脚本时,它会显示图像,但当我尝试使用ajax调用它时,什么都不会发生。

试试下面的代码:

  while ($p = mysqli_fetch_array($photoFile)){
           $img_arr[]= '<img class="image" src='."../img/".$p['photoFile'].".jpeg />";
  };
echo json_encode($img_arr);
exit;
请尝试以下代码:

  while ($p = mysqli_fetch_array($photoFile)){
           $img_arr[]= '<img class="image" src='."../img/".$p['photoFile'].".jpeg />";
  };
echo json_encode($img_arr);
exit;
你能试试这个吗,使用$'imageBox'.htmldata;而不是$'imageBox'。appendDatadata

在getImages.php中

    <?php

    $con = @mysqli_connect('myhost','myusername','myuserpass','myuserDB') or die('Could not connect to the database.'." ". __FILE__ ." ". __LINE__);

    $photoFile = mysqli_query($con, 'select photoFile from photoInfo');
    while ($p = mysqli_fetch_array($photoFile)){
        echo '<img class="image" src="../img/'.$p['photoFile'].'.jpeg" />';
    };
    mysqli_close($con);

    ?>
你能试试这个吗,使用$'imageBox'.htmldata;而不是$'imageBox'。appendDatadata

在getImages.php中

    <?php

    $con = @mysqli_connect('myhost','myusername','myuserpass','myuserDB') or die('Could not connect to the database.'." ". __FILE__ ." ". __LINE__);

    $photoFile = mysqli_query($con, 'select photoFile from photoInfo');
    while ($p = mysqli_fetch_array($photoFile)){
        echo '<img class="image" src="../img/'.$p['photoFile'].'.jpeg" />';
    };
    mysqli_close($con);

    ?>

将断点放在来自服务器[您的php脚本]的数据中,并进行检查,其格式是否正确。

将断点放在来自服务器[您的php脚本]的数据中,并进行检查,其格式是否正确。

使用.htmldata进行检查。代码似乎没有问题。只要试着把完整的路径放在image src中,然后用.htmldata检查一下,代码似乎没有什么问题。只要试着把完整的路径放在图片src中,然后试一下。在清理完我的php脚本后,感谢你和Harish!切换到.html成功了。非常感谢。在清理完我的php脚本后,感谢您和Harish!切换到.html成功了。非常感谢。
<script type="text/javascript">
    $(document).ready(function() {

            $.ajax({
                url: 'php/getImages.php',            
                method: 'get',
                dataType: 'html'
            }).done(function(data){
                $('#imageBox').html(data);
            });
        });

</script>


  <div id="imageBox"></div>
    <?php

    $con = @mysqli_connect('myhost','myusername','myuserpass','myuserDB') or die('Could not connect to the database.'." ". __FILE__ ." ". __LINE__);

    $photoFile = mysqli_query($con, 'select photoFile from photoInfo');
    while ($p = mysqli_fetch_array($photoFile)){
        echo '<img class="image" src="../img/'.$p['photoFile'].'.jpeg" />';
    };
    mysqli_close($con);

    ?>