【问题标题】:proxy in Ext js return error SyntaxError: expected expression, got '<'Ext js 中的代理返回错误 SyntaxError: expected expression, got '<'
【发布时间】:2020-05-16 13:04:46
【问题描述】:

我是 Extjs 的新手。我有一个 test.js.php 页面,其中的一部分是 Ext.data.Store

this.store2 = new Ext.data.Store({
    fields : ["Pid","bid"],
    proxy : {
        type: 'jsonp',
        url:  '../d/sample.data.php?task=GetUser',
        reader: {
            root: 'rows',
            totalProperty: 'totalCount'
        }
    }
});

../d/sample.data.php 页面中,我有这个:

$task = isset($_POST ["task"]);
if($task == "GetUser")
   GetUser();


function GetUser() {

  $dt = array();
  $dt = array_merge($dt, Pdo::runquery("select PID , bid from mytable where PID  = ? ", array($_SESSION['PID'])));

  echo dataReader::getJsonData($dt, count($dt), $_GET["callback"]);
  die();
}

这些代码在站点中运行良好,但在我的 virtualHost 中运行不正常。当我在 localhost 中运行时,在控制台中收到此消息: SyntaxError: expected expression, got ' 它引用了 sample.data.php:1

我在下面尝试 /var/www/myVirtualHostName 中的所有文件:

chmod 777 -R ./* 

ps: 我正在使用 ubuntu 20.04 、虚拟主机、php5.6 和 apache2

【问题讨论】:

    标签: php linux apache2


    【解决方案1】:

    为什么需要 jsonp 代理?在这种情况下,最好使用带有 JSON 阅读器的标准 AJAX 代理。比如:

    this.store2 = Ext.create('Ext.data.Store', {
    fields : ["Pid","bid"],
    proxy : {
        type: 'ajax',
        url:  '../d/sample.data.php?task=GetUser',
        reader: {
            type: 'json',
            root: 'rows',
            totalProperty: 'totalCount'
        }
    }
    });
    

    JsonP 用于跨域请求。

    【讨论】:

      猜你喜欢
      • 2015-11-02
      • 1970-01-01
      • 2022-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-13
      • 2017-07-03
      • 2019-05-11
      相关资源
      最近更新 更多