我正在使用 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