weixin_33738555 2013-12-23 16:45 采纳率: 0%
浏览 101

jQuery + Python响应数据

The following jQuery will call a Python script. The Python script is able to receive the post data. However, the jQuery is unable to receive the response by the Python script.

$(document).ready(function(){
  $("#dd").blur(function(){
    $.post("http://127.0.0.1:8000/validation/trial/",
    {
      dd:document.getElementById("dd").value
    },
    function(data){
      alert("Data: " + data);
    });
  });
});

The following is the python script:

def trial(request):
    dd = request.POST.get('dd')
    print dd
    return HttpResponse(dd)
  • 写回答

2条回答

  • weixin_33709590 2013-12-23 16:49
    关注

    In Django, printing things does not send them back to the client; you need to actually return a response. See the Django tutorial part 3:

    from django.http import HttpResponse
    
    def index(request):
        return HttpResponse("Hello, world. You're at the polls index.")
    
    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办