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

时间:2014-05-25 13:47:12

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

我一直在尝试使用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代码段

<?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;

从谷歌应用引擎登录。

默认:&#34; GET /css/jquery.dataTables.css HTTP / 1.1&#34; 304 -

默认:&#34; GET /php/genjsonphp.php HTTP / 1.1&#34; 200 675

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

谢谢, 萨钦

2 个答案:

答案 0 :(得分:0)

从您的yaml配置中,很明显,要执行php / genjsonphp.php,您需要请求url&#39; / php / genjson&#39;而不是&#39; ./php/genjsonphp.php&#39;就像你的js目前一样。无论是修复配置还是修复js,这都是微不足道的,如果你真的花了很多时间调试&#34;对不起,你可能会有所帮助。

答案 1 :(得分:0)

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