Ajax和PHP调试 [英] Ajax and PHP debug

查看:96
本文介绍了Ajax和PHP调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

构建一个脚本,该脚本一旦在日期选择器日历中选择了日期,便会使用ajax将选定的日期发布到php脚本中;

Building a script that once a date is selected in a datepicker calendar, it uses ajax to post the selected date in a php script;

在该ajax调用成功后,它使用另一个ajax调用将相同的选定日期发布到另一个php脚本,并将其显示在页面中.

in the success of that ajax call, it uses another ajax call to post the same selected date to another php script and displays that in the page.

进行了一些研究,这似乎是我尝试做的最好的解决方案.

Did some research around and this seemed to be the best solution for what I try to do.

脚本如下:

<script> //for the events
    jQuery(function($) {

  $(".date").datepicker({
    onSelect: function(dateText) {
      display("Selected date: " + dateText + "; input's current value: " + this.value);
      $(this).change();
    }
  }).on("change", function() {
    display("Got change event from field");
    // call next ajax function

    var mydate = this.value;
    $.ajax({
        type: "POST",
        url: 'boxes_script.php',
        data: ({dates: mydate}),
            dataType : 'html',
        success: function(data) {
            $('.caixas').html(data);
            alert(data);
            $.ajax({
                type: "POST",
                url: 'events_script.php',
                data: ({dates1: mydate}),
                    dataType : 'html',
                success: function(data) {
                    $('.results-ajax').html(data);
                alert(data);
                }
            });
        }
    });

});
  function display(msg) {
    $("<p>").html(msg).appendTo(document.body);
  }

});
    </script>

这是atm所使用的代码.由于此处提供了反馈,因此进行了一些更新,但该解决方案仍无法100%正常工作

有一个问题,我认为这是因为第二个Ajax调用位于成功的Ajax内部.

There's a problem on it and I think it's because the second Ajax call is inside of a success Ajax.

问题在于以下: 数据被发布在php脚本中,该脚本的运行方式与应有的方式相同. 该阵列将填充正确的信息.

The problem is the following: The data is being posted in the php scripts, which run like how they should. The array gets populated with the right information. The

$('.caixas').html(data);

$('.caixas').html(data);

工作正常,并在其中显示"boxes_script.php"中的数据.

works fine and displays data from 'boxes_script.php' there.

The

$('.results-ajax').html(data);

$('.results-ajax').html(data);

接收"events_script.php"发送的数据的100%,但是出于任何奇怪的原因,请不要将其附加到页面上.

receives 100% of the data being sent from 'events_script.php' but for any weird reason, doesn't append it to the page..

我可以在警报消息中看到数据,这是发送到浏览器的正确数据.

I can see the data in alert messages and it's the right data being sent to the browser.

为什么不将数据附加到页面上?

Why isn't that data being appended to the page?

这是'events_script.php'的php代码:

This is the php code for 'events_script.php':

<?php
include 'config/config.php';
include 'libraries/database.php';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
  print_r($_POST);
  echo $_POST[dates1];

    $dias= $_POST[dates1];
    $mysql_date = date('Y-m-d', strtotime($dias));
    echo $mysql_date;

   //Make database query
   $sql = "***";

    $result = mysqli_query($conn, $sql);
    if (mysqli_num_rows($result) > 0) {
    while ($row = mysqli_fetch_assoc($result)) {
        $image = $row['Company_Logo'];
        $myArray = json_decode($image, true);
        $event=$row['eventID'];
        echo '<div class="tab-pane" role="tabpanel">
                          <div id="'.$dias.'"  class="container day-events">
                                <div class="row event-list">
                                    <div class="event-list-time col-md-3 col-sm-3 center" style="background-image:url('.$myImage = $myArray[0]['name'].');">
                                        <p class="event-list-start-time">'.$row['Start_Date'].'</p>
                                        <hr class="event-list-time-divider">
                                        <p class="event-list-end-time">'.$row['End_Date'].'</p>
                                    </div>
                                    <div class="event-list-info col-md-9 col-sm-9">
                                        <h2 class="event-list-name">'.$row['Event_Name'].'</h2>
                                        <p>Organized by <span class="event-list-organizer"><a href="mini-about.php?$company='.$row['Ref_ID'].'">'.$row['Company_Name'].'</a></span></p>
                                        <p class="event-list-description">'.$row['Event_Description'].'</p>
                                        <a href="mini-single-event.php?event='.$event.'"><button type="button" class="btn more-info-list">More Information</button></a>
                                    </div>
                                </div> 
                            </div> 
                        </div>';
        }} else { echo 'No results found.'; }
}
?>

注意:在错误日志中未发现任何错误.网络的状态为200.

Note: no errors were found in the error log. The network gives status 200.

可以在此处看到发送到浏览器的数据:

数据的第一部分已添加到浏览器中,如您在图像中所见.

为什么不能全部正常工作?

Why is not working everything?

推荐答案

这是解决问题并得出以下最终结果的原因:

This was what fixed the problem and made the following final result:

:

<div class="row events-tabs">
     <div class="container" data-example-id="togglable-tabs"> 
         <ul class="nav nav-pills center caixas" id="myTabs" role="tablist">
          </ul> 
         <div class="results-ajax tab-content" id="myTabContent">
         </div> 
     </div>
</div>

新功能:

 <div class="row events-tabs">
      <div class="container" data-example-id="togglable-tabs"> 
           <ul class="nav nav-pills center caixas" id="myTabs" role="tablist">
           </ul> 
           <div class="tab-content" id="myTabContent">
                <div class="results-ajax"></div>
           </div> 
      </div>
 </div>

因此,基本上使用results-ajax作为自己div的类解决了该问题.

So, basically using results-ajax as class of an own div fixed the problem.

这篇关于Ajax和PHP调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆