谷歌应用引擎,AJAX返回PHP文件的内容字符串,而不是JSON


Google App Engine, AJAX is returning string of contents of PHP file insteasd of JSON

我一直试图在GAE中使用PHP作为运行时来工作数据表,但不知何故它返回实际页面内容而不是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片段
<?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的内容片段

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

google app引擎日志。

default: "GET/css/jquery. datatable .css HTTP/1.1" 304 -

默认:"GET/php/genjsonphp.php HTTP/1.1" 200 675

花了很多时间调试,但没有运气,谁能指出错误或文档。

谢谢,萨钦

从你的yaml配置中很明显,要执行php/genjsonphp.php你需要请求url '/php/genjson',而不是'./php/genjsonphp.php',因为你的js目前做的。无论是修复配置还是修复js,这都是微不足道的,如果你真的"花了很多时间调试",你可能无法帮助,对不起。

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