Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

273
Visualizações
How can I separate button operation in javascript and Django?

I made sign up form page using Django. When I fill in the register form, data is included in database. But, when I click the email check button, register button also is clicked and the page is reloaded. How can I separate these two button?

$('.email-check-btn').click(function (){
    const email = $('#email').val()
    if (email === ''){
        alert('please check the form')
    }

    $.ajax({
        type: 'GET',
        url: 'email-check?email=' + email,
        datatype: 'json',
        success: function (response){
            if (response.result !== 'success') {
                alert(response.data)
                return
            }
            if (response.data === 'exist') {
                alert('that email is already exist!')
                $('#email').val('').focus()
            } else {
                alert('good, you can use it!!')
            }
        }
    })
})
def email_check(request):
    try:
        user = get_user_model().objects.get(email=request.GET['email'])
    except Exception as e:
        user = None

    result = {
        'result': 'success',
        'data': 'not exist' if user is None else 'exist'
    }
    return JsonResponse(result)
def sign_up(request):
    if request.method == 'GET':
        user = request.user.is_authenticated
        if user:
            return redirect('/main')
        else:
            return render(request, 'sign_in_and_up.html')

    elif request.method == 'POST':
        user_id = request.POST.get('username', '')
        password = request.POST.get('password', '')
        password2 = request.POST.get('password2', '')
        nickname = request.POST.get('nickname', '')
        email = request.POST.get('email', '')

        if password != password2:
            return render(request, 'sign_in_and_up.html', {'error': 'check your password'})
        else:
            if user_id == '' or password == '' or nickname == '' or email == '':
                return render(request, 'sign_in_and_up.html', {'error': 'fill in all the blank'})

            exist_user = get_user_model().objects.filter(username=user_id)
            if exist_user:
                return render(request, 'sign_in_and_up.html', {'error': 'already exist'})
            else:
                UserModel.objects.create_user(username=user_id, password=password, nickname=nickname, email=email)
                return render(request, 'sign_in_and_up.html')

error code

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda