您好,我有一个 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 调用中获得与控制台结果相同的结果?
谢谢。