【发布时间】:2013-07-21 05:38:16
【问题描述】:
您好,我有一个 python 脚本,我正在尝试使用这样的 AJAX 调用从客户端从 PHP 运行:
$.ajax({
async: false,
cache:false,
url:"callpython.php",
type: "POST",
data: "data1=" + path + "&data2=" + clr[k0],
success: function (response) {
console.log(response);
}});
callpython.php里面的代码是:
<?php
exec("python myscript.py",$return);
echo json_encode($return);
?>
而myscript.py里面的代码是:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import string
import cgi, cgitb
from lxml import etree
from PIL import Image
pet="images/rock1.png"
petColor="59A678"
.//The rest of the code that populates the variables printed down below
.
.
.
print "Content-type: text/html"
print
print eyeSize
print displacementX
print displacementY
print distance
print textX
print textY
print sizeText
print colorText
作为 Ajax 结果我得到:Array
当我从控制台运行 php 代码时:php callpython.php 它执行 python 脚本并给我:["Content-type: text\/html","","30","37","47","20","27","40","20","#91806F"]
但是当使用 ajax Firebug 调用同一个 php 文件时,结果显示:[]。
那么请问如何在 Ajax 调用中获得与控制台结果相同的结果?
谢谢。
【问题讨论】: