【问题标题】:Why doesn't python Dajaxice function recognize when HTML sends argument(s)?为什么当 HTML 发送参数时 python Dajaxice 函数不能识别?
【发布时间】:2014-01-13 04:00:45
【问题描述】:

这行得通:

Javascript:
    function my_js_callback(data) {alert("Response = " + data.response);}
HTML:
    <input id="myID" type="text" name="myID" onblur="Dajaxice.myApp.myAjaxFunction(my_js_callback);"/>
Python:
    @dajaxice_register()
    def myAjaxFunction(request):
        return simplejson.dumps({'response': True})

但是,当我向 Ajax 函数添加一个参数并从 HTML 调用它时,它不起作用:

Javascript:
    function my_js_callback(data) {alert("Response = " + data.response);}
HTML:
    <input id="myID" type="text" name="myID" onblur="Dajaxice.myApp.myAjaxFunction(my_js_callback,{'myArgument':3});"/>
Python:
    @dajaxice_register()
    def myAjaxFunction(request, myArgument):
        return simplejson.dumps({'response': True})

这是它产生的错误:

TypeError: myAjaxFunction() takes exactly 2 arguments (1 given)

为什么不将第二个参数传递给 myAjaxFunction()?如何让 myAjaxFunction 识别我要发送的内容?

【问题讨论】:

    标签: python django dajaxice


    【解决方案1】:

    我找到了答案。 我需要将 method='GET' 添加到装饰器中。然后它起作用了:

    @dajaxice_register(method='GET')
    

    【讨论】:

      猜你喜欢
      • 2019-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-22
      • 2012-06-06
      • 1970-01-01
      • 1970-01-01
      • 2018-01-20
      相关资源
      最近更新 更多