使用javascript提交一个django表单 [英] submitting a django form using javascript

查看:132
本文介绍了使用javascript提交一个django表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < form id =myformname =myformaction = 方法= POST > 
< a href =javascript:document.forms ['myform']。submit(); name =myform>提交
< / a>
< / form>

我使用href和一些javascript提交表单到我的django服务器。
在服务器上,我使用以下代码检查发布请求 -

  if request.POST中的'myform' 
'''处理表单submition'''
返回True
返回False

这将返回false。任何想法为什么?

解决方案

这种形式中是否有任何输入字段?你应该检查,而不是表单的名称。表单本身没有任何内容,所以发布了哪些数据?即名为someData的文本输入字段。 if request.POST中的'someData':


ok so have this snippet of code -

    <form id="myform" name="myform" action="." method="post">
        <a href="javascript: document.forms['myform'].submit();" name="myform">Submit
        </a>
    </form>    

i am submitting a form using an href and some javascript to my django server. on the server i check the post request using the following code -

    if 'myform' in request.POST:
        '''handle the form submition'''
        return True
    return False

this returns false. any ideas why?

解决方案

Are there any input fields in this form? You should be checking for that rather than the name of the form. The form itself is nothing, so what data is being posted? i.e. a text input field named someData. if 'someData' in request.POST:

这篇关于使用javascript提交一个django表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆