weixin_33675507 2017-02-06 14:24 采纳率: 0%
浏览 41

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;

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.

The script is the following:

<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>

This is the code being used atm. Got some updates because of the feedback given here, but the solution still hasn't worked 100%

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

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);

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

The

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

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?

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.'; }
}
?>

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

The data can be seen sent to the browser here:

enter image description here

The first part of the data is being appended to the browser, as you can see in the images.

enter image description here

Why is not working everything?

  • 写回答

3条回答

  • weixin_33713503 2017-02-06 14:29
    关注

    Change

    data1: ({dates1: this.value})

    to

    data: ({dates1: this.value})
    
    评论

报告相同问题?

悬赏问题

  • ¥15 vscode的问题提问
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM