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

181
Visualizações
How can access input value in django view through AJAX without form submission

I am beginner in django.I am working on a single text box in a django form which have number of fields.I wrote AJAX code for passing each value(entered from keyboard). How can i access this value in django class based view code. I want to save this value into a variable. Here i am trying to check given text is already existing or not. checking is done for each keyboardinput.

$(document).ready(function () {
    $('#s_id > input').on('input',function(e){
        console.log(e);
        s_text = e.target.value;
        $.ajax({
            type: 'POST',
            url: "{% url 'create-studentpage' %}",
            data: s_text,

            success: function (response) {
                console.log("response", response);
                
            },
            error: function (response) {
                console.log("error", response.responseJSON.error);
                
                
            }
        })
    });
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You should change the format of data you have in a json format so that you can embed csrf_middleware_token into the POST :

$(document).ready(function () {
    $('#s_id > input').on('input',function(e){
        console.log(e);
        s_text = e.target.value;
        $.ajax({
            type: 'POST',
            url: "{% url 'create-studentpage' %}",
            data: {"text": s_text, 'X-CSRFToken': {{csrf_token}} },

            success: function (response) {
                console.log("response", response);
                
            },
            error: function (response) {
                console.log("error", response.responseJSON.error);
                
                
            }
        })
    });

And then in backend, you can access it by using request.POST["text"]

about 4 years ago · Juan Pablo Isaza Relatório
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