从jquery调用python,无法获得POST参数

时间:2012-09-30 02:49:50

标签: jquery python post

以下是javascript代码:

$.ajax({
  type: 'POST',
  url: '/vote_selection/vote/',
  dataType:'json',
  data: {'message':'123'},
  success:function(data){
    alert(data);
  }
});

下面是python代码:

def vote_select(request):
    print "1"
    print request
    print request.method
    print request.POST
    return HttpResponse("1",mimetype='text/plain')

输出

1

, POST:, ...  'REQUEST_METHOD':'GET', ..

GET

[29 / Sep / 2012 22:38:49]“GET / vote_selection / vote / HTTP / 1.0”200 1

为什么该方法变为GET,为什么GET或POST中没有params?

谢谢!

1 个答案:

答案 0 :(得分:0)

试试这个:

import json    
def vote_select(request):
        print "1"
        print request
        print request.method
        print request.POST
        return HttpResponse(json.dumps({ 'somevalue': 1 }),mimetype='application/json')