$("#reg_submit").click(function () { var data = new FormData(); var username = $("#id_username").val(); var password = $("#id_password").val(); var re_password = $("#id_re_password").val(); var phone = $("#id_phone").val(); var email = $("#id_email").val(); var avatar = document.getElementById("id_avatar").files[0]; data.append("username",username); data.append("password",password); data.append("re_password",re_password); data.append("phone",phone); data.append("email",email); data.append("avatar",avatar); data.append("csrfmiddlewaretoken",$("[name=csrfmiddlewaretoken]").val()); $.ajax({ url:"/register/", type:"POST", data:data, dataType:"JSON", processData:false, contentType:false, success:function (data) { if(data.status) { location.href = "/login/"; } else { $.each(data.msg,function (k,v) { $("#id_" + k).next().text(v).parent().parent().addClass("has-error") }) } } }) });