猿问

使用Ajax从python获取数据

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


HUH函数
浏览 208回答 2
2回答

Helenr

您不能SimpleHTTPServer用于网络应用。它不执行任何代码,仅提供原始文件(这就是为什么您仅设法获取脚本文本的原因)。
随时随地看视频慕课网APP

相关分类

Python
我要回答