html
<form action="/jobseeker/profile/" method="post" id="langForm">
<input type="hidden" name="curform" value="langform">
<div class="control-group">
<label class="control-label">Language Name</label>
<div class="controls">
<input id="languageadd" maxlength="120" name="language" type="text" required/>
</div>
</div>
<input class="btn btn-success" type="submit" value="save" />
</form>
jQuery脚本
$("#langForm").on("submit", function(event){
$.post('/jobseeker/profile/', $(this).serialize(),
function(data){
alert('AJAX successful');
//CreateRow(jdata);
}, "json");
event.preventDefault();
});
/ jobseeker / profile /的views.py
def addlang(request):
#curform=request.POST['curform']
md=Languages()
for i in request.POST.keys():
if i=='curform':continue
setattr(md,i,request.POST[i])
md.save()
n={
"pk": md.pk,
"lang":md.language,
"read":md.read,
"speak":md.speak,
"write":md.write
}
return HttpResponse(json.dumps(n), mimetype="application/json")
当我单击“提交”按钮时,防止默认设置不起作用,并且整个表单都将提交
javascript大神给出的解决方案
尝试返回false;
$("#langForm").on("submit", function(event){
$.post('/jobseeker/profile/', $(this).serialize(),
function(data){
alert('AJAX successful');
//CreateRow(jdata);
}, "json");
return false;
});
Mongo汇总 - javascript我的收藏中有以下文件{ "_id": ObjectId("54490b8104f7142f22ecc97f"), "title": "Sample1", "slug": "samplenews", "cat": …
如何从客户端将数据插入数据库? - javascript我是Web开发的初学者,可以访问cpanel上托管的网站,并且需要对其进行一些更改。这个网站的后端是由蛋糕PHP制作的,我想使用ajax从客户端将一些数据插入其数据库。问题是我不知道如何获取负责插入数据库的PHP文件的URL。参见下面的代码:var xhttp = newXMLHttpRequest(); xhttp.onreadystatechange= …
执行onclick时获得意外令牌 - javascript我正在使用onclick事件从PHP调用JS函数。这是我的代码:我在一个函数中,因此我需要通过PHP来完成它,因为然后我会返回:$html = '<input type="checkbox" checked value="1" id="setGetSku" name="se…
为HTML表单GET方法添加其他文本 - javascript使用表单的“ get”方法时,<form action="domain.com" method="get"> Surname: <input type="text" name="ABC"><br> Name: <input type=…
我如何使用flask从javascript获取变量 - javascript因此,我按照flask的建议在相应的文件夹中设置了app.py,index.js,index.html。 Index.html在app.py运行时呈现,然后index.html运行index.js,后者从用户那里获取输入数据。我试图发送此输入并将其发送到python,在这里我可以调用API,获取数据并使用它,但是我想不出一种方法来做到这一点。我的app.py…