weixin_33739523 2017-02-27 12:33 采纳率: 0%
浏览 31

PHP jQuery使用命名空间

First of all, is PHP's NAMESPACE and USE features compatible with making jQuery ajax requests to handle and return data?

I have set the jQuery AJAX request and PHP handlers up but the code fails at the first hurdle when I make a request to DFP's API. NAMESPACE and USE are declared at top of the php script that the jQuery is being sent to.

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

require 'vendor/autoload.php';

Error that comes out -

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

In short that's what happens when the namespaces aren't working when making a request.

If it is possible what tools do I need to make sure NAMESPACE and USE are respected by the jQuery request.

Is there a preference in this scenario to use a particular data type in jQuery to better handle the request like xml, json, script, or 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> 
  • 写回答

1条回答 默认 最新

  • 衫裤跑路 2017-02-27 17:08
    关注

    The issue didn't really have anything to do with my code.

    It was the path I was using to direct the ajax request to. Because I am using a WordPress framework the request needed to be made a a relative URL using path templates within WordPress. So instead of using a absolute URL I used a WordPress based one and everything worked flawlessly.

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

    Instead of

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

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)