【发布时间】:2013-07-31 14:52:28
【问题描述】:
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();
});
views.py for /jobseeker/profile/
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")
当我点击提交按钮时,防止默认不工作和整个表单提交发生
【问题讨论】:
-
浏览器控制台是否有错误
-
@ArunPJohny Uncaught TypeError: Object [object Object] has no method 'ajaxForm'
-
@ArunPJohny
Uncaught TypeError: Object [object Object] has no method 'ajaxForm' localhost:8000/jobseeker/profile/:236 (anonymous function) localhost:8000/jobseeker/profile/:236 c jquery.js:3 p.fireWith jquery.js:3 b.extend.ready jquery.js:3 H -
@ArunPJohny 抱歉,我有一些拼写错误 ss
标签: javascript jquery python django post