Bootstrap和PHP中具有AJAX的模块

问题描述 投票:0回答:1

我已经阅读了其他几个具有相同问题的主题,但我找不到自己的错误。

<script>
        $(document).ready(function(){

            $('.orderdetails').click(function(){

            var userid = $(this).data('id');

            // AJAX request
            $.ajax({
            url: 'ajax.php',
            type: 'post',
            data: {orderid: orderid},
            success: function(data){ 
                // Add response in Modal body
                $('.modal-body').html(data);

                // Display Modal
                $('#OrderDetails').modal('show'); 
            }
            });
            });
            });
    </script>

此脚本标记与模态在同一页上运行,模态如下所示:

<div class="modal fade" id="OrderDetails" role="dialog">
<div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4 class="modal-title">Order Details</h4>
                </div>
                <div class="modal-body">
                </div>

                <div class="modal-footer">
                </div>
        </div>
    </div>
</div>

从ajax.php的输出中,我得到的是干净的html,甚至尝试删除所有内容并仅放入echo“ test string”;(此时,我不使用post变量,只是想要使其正常运行)并获取弹出窗口的模式,但没有任何内容。还尝试将所有输出ajax.php放入一个名为response的变量中,并在运气好的情况下将jquery中的(data)替换为(response)。

编辑:

我的ajax.php内容

<?php 
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once("vendor/autoload.php"); 

use Automattic\WooCommerce\Client;
use Automattic\WooCommerce\HttpClient\HttpClientException;
$woocommerce = new Client(
    'https://danielacevedo.com/store-sandbox',
    'KEY',
    'KEY2',
    [
        'wp_api' => true,
        'version' => 'wc/v2'
        
    ]
);


try {

	$details = $woocommerce->get('orders/94');
	$query = ['date_min' => '2017-10-01', 'date_max' => '2025-10-30'];

	$lastRequest = $woocommerce->http->getRequest();
	$lastRequest->getUrl(); // Requested URL (string).
	$lastRequest->getMethod(); // Request method (string).
	$lastRequest->getParameters(); // Request parameters (array).
	$lastRequest->getHeaders(); // Request headers (array).
	$lastRequest->getBody(); // Request body (JSON).

	$lastResponse = $woocommerce->http->getResponse();
	$lastResponse->getCode(); // Response code (int).
	$lastResponse->getHeaders(); // Response headers (array).
	$lastResponse->getBody(); // Response body (JSON).
}

catch(HttpClientException $e) {
	$e->getMessage(); // Error message.
	$e->getRequest(); // Last request data.
	$e->getResponse(); // Last response data.
}

?>


             <div class="container">
                              <h2 class="sub-header">Order detail</h2>
                                <div class='table-responsive'>
                                    <table id='myTable' class='table table-striped table-bordered'>
                                        <thead>
                                            <tr>
                                                <th></th>
                                                <th>Order #</th>
                                                <th>Customer</th>
                                                <th>Address</th>
                                                <th>Contact</th>
                                                <th>Order Date</th>
                                                <th>Status</th>
                                                <th>Actions</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php 

                echo "<tr><td>";
                
                foreach($details->shipping_lines as $shipping_details){
                    if ($shipping_details->method_id == 'local_pickup'){
                        echo "<i class='fas fa-store-alt'></i>";
                    }
                    if ($shipping_details->method_id == 'flat_rate') {
                        echo "<i class='fas fa-motorcycle'></i>";
                    }
                    else {
                        
                    }
                }

                echo "</td>";
                echo "     <td>" . $details->id ."</td>
                          <td>" . $details->billing->first_name . " " . $details->billing->last_name ."</td>
                          <td>" . $details->shipping->address_1 ."</td>
                          <td>" . $details->billing->phone ."</td>
                          <td>" . date("jS F, Y g:i a", strtotime($details->date_created)) ."</td>
                          <td>" . $details->status ."</td>
                          </tr>";
                ?>
                                        </tbody>
                                    </table>
                                </div>
               </div>
php ajax bootstrap-modal
1个回答
-1
投票

更容易;-)

© www.soinside.com 2019 - 2024. All rights reserved.