【问题标题】:Google App Engine, AJAX is returning string of contents of PHP file insteasd of JSONGoogle App Engine,AJAX 正在返回 PHP 文件的内容字符串而不是 JSON
【发布时间】:2014-05-25 13:47:11
【问题描述】:

我一直在尝试使用 PHP 作为运行时在 GAE 中处理数据表,但不知何故它返回的是实际页面内容而不是 json 响应。以下是 app.yaml 文件。

application: app353
version: 1
runtime: php
api_version: 1
threadsafe: yes

handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico

- url: /css
static_dir: css

- url: /js
static_dir: js

- url: .*
script: index.php

- url: /php/genjson
script: php/genjsonphp.php

PHP/HTML sn-p

<?php

?> 
<script src="./js/jquery.js"></script>
<script type="text/javascript" language="javascript" src="./js/jquery.dataTables.js">     
</script>
<link rel="stylesheet" type="text/css" media="all" href="./css/jquery.dataTables.css" /> 


<script>
$(document).ready(function() 
{    
$('#example').dataTable( 
{  
 "ajax": './php/genjsonphp.php' 
 } );
} );
</script>


 <table class="display" id="example">
 <thead>
 <th>Dimensions</th>

 </thead>
 <tbody></tbody>
 </table> 

目录结构如下

css/*.css
js/*.js
php/genjsonphp.php
app.yaml
index.php

来自 getjsonphp.phh 的内容 sn-p

header('Content-Type: application/json');
var_dump(json_decode($strjSon));
header('Content-Type: application/json');
echo $strjSon;

来自谷歌应用引擎的日志。

默认值:“GET /css/jquery.dataTables.css HTTP/1.1”304 -

默认值:“GET /php/genjsonphp.php HTTP/1.1”200 675

花了很多时间调试但没有运气有人可以指出错误或文档。

谢谢, 萨钦

【问题讨论】:

  • 你的要求是什么?您得到的响应是什么(请包括请求和响应您问题的标题和正文)。

标签: php jquery ajax json google-app-engine


【解决方案1】:

从您的 yaml 配置很明显,要执行 php/genjsonphp.php,您需要请求 url '/php/genjson' 而不是 './php/genjsonphp.php',就像您的 js 当前所做的那样。要么修复配置,要么修复 js,这很简单,如果你真的“花了很多时间调试”,你可能会无能为力,抱歉。

【讨论】:

    【解决方案2】:

    .* url 映射将优先于 /php/genjson,具体取决于它们在 app.yaml 文件中指定的顺序。如果 php/genjsonphp.php 是您尝试调用的实际脚本,则需要相应地进行更改。

    【讨论】:

      猜你喜欢
      • 2013-03-23
      • 2022-12-06
      • 2013-10-19
      • 2014-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-17
      • 1970-01-01
      相关资源
      最近更新 更多