我是 python 和 django 的初学者。
我想禁用 HTML“注册”按钮。一旦“插件注册成功”,就会出现此消息。
目前我正在使用
以 json 响应返回消息return JsonResp(request,message=_('vCenter plugin registered successfully.'),)
这是代码..
def vcp_home(request):
if request.method == 'POST':
form = VcenterConfigurationForm(request.POST)
if form.is_valid():
if form.vcp_register():
form.save()
extFact=ExtensionRegister.ExtensionFactory()
obj = models.VcenterConfiguration.objects.latest('id')
obj.vc_version=extFact.get_pluginVersion();
obj.save()
form.check_update()
return JsonResp(request,message=_('plugin registered successfully.'),)
else:
return JsonResp(request, error=True, message=_(form.vcp_status))
#return JsonResp(request,message=_(form.vcp_status),)
else:
try:
obj = models.VcenterConfiguration.objects.latest('id')
form = VcenterConfigurationForm(instance=obj)
form.check_update()
except :
form = VcenterConfigurationForm()
form.check_update()
return render(request, "vcp/index.html", {
'form': form
})
最佳答案
一种方法是使用 ajax 提交表单,然后解析响应,然后根据该响应禁用按钮。
<script language="JavaScript">
$(document).ready(function() {
$('#YOUR_FORM').submit(function() {
$.ajax({ // create an AJAX call...
data: $(this).serialize(), // get the form data
type: $(this).attr('method'), // GET or POST
url: $(this).attr('action'), // the file to call
success: function(response) { // on success..
//check the response and disable submit button
}
});
return false;
});
});
</script>
关于javascript - 如何禁用 django 中的 html 按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32249380/