Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在单击按钮后禁用该按钮,并在登录过程完成后通过检查django中的服务器响应来启用该按钮_Python_Django - Fatal编程技术网

Python 如何在单击按钮后禁用该按钮,并在登录过程完成后通过检查django中的服务器响应来启用该按钮

Python 如何在单击按钮后禁用该按钮,并在登录过程完成后通过检查django中的服务器响应来启用该按钮,python,django,Python,Django,我正在使用Django和python中的注册功能。当我点击注册按钮时,该按钮应禁用,成功注册后,它应自动再次启用。如何做到这一点 我尝试使用ajax,但我不知道如何检查服务器的响应,用户是否成功注册。如果您使用的是带有提交按钮的表单,则一旦按下按钮,注册过程将启动,并在成功注册后加载您告诉它的页面 如果您正在使用javascript/ajax或类似的方法将信息发送到后端,然后在可以禁用按钮时返回(其中btnSubmit是id,您正在使用JQuery): 当您从Django use获得返回json

我正在使用
Django
python
中的注册功能。当我点击注册按钮时,该按钮应禁用,成功注册后,它应自动再次启用。如何做到这一点


我尝试使用ajax,但我不知道如何检查服务器的响应,用户是否成功注册。

如果您使用的是带有提交按钮的表单,则一旦按下按钮,注册过程将启动,并在成功注册后加载您告诉它的页面

如果您正在使用javascript/ajax或类似的方法将信息发送到后端,然后在可以禁用按钮时返回(其中btnSubmit是id,您正在使用JQuery):

当您从Django use获得返回json时

$("#btnSubmit").attr("disabled", false);
您的总体脚本如下所示:

function myFunction() {
    $("#btnSubmit").attr("disabled", true);
    var info = [];
    info[0] = $('#username').val();
    info[1] = $('#password').val();

    $.ajax({
        url : "/some_url/", // the endpoint
        type : "POST", // http method
        data : { info : info }, // data sent with the post request
        // handle a successful response
        success : function(json) {
            // do stuff
            $("#btnSubmit").attr("disabled", false);
        },
        // handle a non-successful response
        error : function(xhr,errmsg,err) {
            $('#results').html("<div class='alert-box alert radius' data-alert>Oops! We have encountered an error: "+errmsg+
                " <a href='#' class='close'>&times;</a></div>"); // add the error to the dom
            console.log(xhr.status + ": " + xhr.responseText); // provide a bit more info about the error to the console
        }
    });
}
函数myFunction(){
$(“#btnSubmit”).attr(“禁用”,真);
var信息=[];
信息[0]=$('#用户名').val();
信息[1]=$(“#密码”).val();
$.ajax({
url:“/some\u url/”,//端点
类型:“POST”//http方法
数据:{info:info},//随post请求发送的数据
//处理成功的响应
成功:函数(json){
//做事
$(“#btnSubmit”).attr(“禁用”,false);
},
//处理不成功的响应
错误:函数(xhr、errmsg、err){
$('#results').html(“哎呀!我们遇到了一个错误:”+errmsg+
“”);//将错误添加到dom
log(xhr.status+“:“+xhr.responseText);//向控制台提供有关错误的更多信息
}
});
}

如果您正在使用带有提交按钮的表单,则一旦按下按钮,注册过程将开始,并将在成功注册后加载您告诉它的页面

如果您正在使用javascript/ajax或类似的方法将信息发送到后端,然后在可以禁用按钮时返回(其中btnSubmit是id,您正在使用JQuery):

当您从Django use获得返回json时

$("#btnSubmit").attr("disabled", false);
您的总体脚本如下所示:

function myFunction() {
    $("#btnSubmit").attr("disabled", true);
    var info = [];
    info[0] = $('#username').val();
    info[1] = $('#password').val();

    $.ajax({
        url : "/some_url/", // the endpoint
        type : "POST", // http method
        data : { info : info }, // data sent with the post request
        // handle a successful response
        success : function(json) {
            // do stuff
            $("#btnSubmit").attr("disabled", false);
        },
        // handle a non-successful response
        error : function(xhr,errmsg,err) {
            $('#results').html("<div class='alert-box alert radius' data-alert>Oops! We have encountered an error: "+errmsg+
                " <a href='#' class='close'>&times;</a></div>"); // add the error to the dom
            console.log(xhr.status + ": " + xhr.responseText); // provide a bit more info about the error to the console
        }
    });
}
函数myFunction(){
$(“#btnSubmit”).attr(“禁用”,真);
var信息=[];
信息[0]=$('#用户名').val();
信息[1]=$(“#密码”).val();
$.ajax({
url:“/some\u url/”,//端点
类型:“POST”//http方法
数据:{info:info},//随post请求发送的数据
//处理成功的响应
成功:函数(json){
//做事
$(“#btnSubmit”).attr(“禁用”,false);
},
//处理不成功的响应
错误:函数(xhr、errmsg、err){
$('#results').html(“哎呀!我们遇到了一个错误:”+errmsg+
“”);//将错误添加到dom
log(xhr.status+“:“+xhr.responseText);//向控制台提供有关错误的更多信息
}
});
}

您好,谢谢您的回复。我可以只使用javascript而不使用ajax吗?如何使用Django获得回复?您好,谢谢您的回复。我可以只使用javascript而不使用ajax吗?如何使用Django获得响应?