3

我正在使用 ajax 将数据传递给 python 脚本,但我无法取回该数据。我设法得到的最多的是'未定义'或脚本文本本身(不知道为什么......)。目前,经过多次尝试,我一无所获。

我不知道这是否相关,但我是 python 新手,不想使用任何框架,所以我使用 SimpleHTTPServer。反正...

这是ajax调用

$(function(){
    $.ajax({
        type: "GET",
        url: "con-test.py",
        dataType: "json",
        success: function (responseText) {
            alert(responseText); /* responseText.stuff is not working either */
        }
    });
});

和脚本 con-test.py

import json

result = {}
result['stuff'] = 'banana'
json_string = json.dumps(result)

print result # also tried return result
4

1 回答 1

1

您不能SimpleHTTPServer用于网络应用程序。它不执行任何代码,它只是提供原始文件(这就是为什么您只能设法获取脚本文本)。我建议使用一些网络框架;看到这个问题

于 2013-06-09T19:21:31.370 回答