PHP jQuery 使用命名空间

PHP jQuery Use Namespace

首先,PHP 的 NAMESPACEUSE 功能是否兼容 jQuery ajax 请求处理和 return 数据?

我已经设置了 jQuery AJAX 请求和 PHP 处理程序,但是当我向 DFP 的 API 发出请求时,代码在第一个障碍处失败。 NAMESPACEUSE 在发送 jQuery 的 php 脚本的顶部声明。

use Google\AdsApi\Dfp\v201611\DFPLineItems;
use Google\AdsApi\Dfp\v201611\GetAvailabilityForecast;

require 'vendor/autoload.php';

出现错误 -

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'file does not exist'.

简而言之,这就是在发出请求时命名空间不起作用时发生的情况。

如果可能的话,我需要什么工具来确保 NAMESPACEUSE 得到 jQuery 请求的尊重。

在这种情况下是否有偏好使用 jQuery 中的特定数据类型来更好地处理 xml、json、脚本或 html 等请求?

    <script>
        jQuery(document).ready(function($) {            
            $(document).on('click','#pbd-alp-load-posts a',function () {
                var country = $('#country').val();;
                $.ajax({
                    type: "POST",
                    url: "<?php echo site_url() ?>/wp-content/themes/truemag-child/orders/fetch.php", 
                    data: {country:country},
                    dataType: "html",
                    success: function(response){
                        $("#response_container").append(response);
                        //$('#pbd-alp-load-posts a').blur();
                        //console.log(page*10);                         
                    }
                });
            return false;
            });
        });
      </script> 

这个问题与我的代码没有任何关系。

这是我用来将 ajax 请求定向到的路径。因为我使用的是 WordPress 框架,所以需要使用 WordPress 中的路径模板将请求设为相对 URL。因此,我没有使用绝对 URL,而是使用基于 WordPress 的,一切都完美无缺。

url: "http://127.0.0.1/wordpress/fetch-inventory/", 

而不是

url: "<?php echo site_url() ?>/wp-content/themes/truemag-child/orders/fetch.php",