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

353
Visualizações
How to use Get and Post method in ajax for modal window in laravel

I have Datatable in which I am getting all the records from database, now I have rendered a feedback button for all the the records. On click of the Feedback button a modal popup window open with option to submit the feedback for particular id. Now as I have rendered Feedback button not sure how to insert the feedback for particular id using ajax. In my database there is Feedback column which have no values as of now, want to insert the value submitted to be inserted in database.

Here is my code how I have rendered Feedback button for all the records.

{
                    
                    render:function(data, type, row){
                       return "<a href='#modal-lg5' data-toggle='modal' data-target='#modal-lg5' class='btn btn-warning btn-sm'>  Feedback </a>"+
            "<div class='modal fade' id='modal-lg5'>"+
                "<div class='modal-dialog modal-lg'>"+
                 "<div class='modal-content'>"+
                    "<div class='modal-header'>"+
                        "<h4 class='modal-title'>Submit Feedback</h4>"+
                        "<button type='button' class='close' data-dismiss='modal' aria-label='Close'>"+
                            "<span aria-hidden='true'>&times;</span>"+
                        "</button>"+
                    "</div>"+
              "<div class='modal-body'>"+
                  "<div class='row'>"+
                    "<div class='col'>"+
                    "<form id='contactForm'>"+
                      "<div class='form-group'>"+
                        "<label>Details:</label>"+
                "<input type='text' name='title' class='form-control' placeholder='details' required=''>"+
            "</div>"+
                      "</div>"+
                      "<button class='btn btn-success'>Submit Feedback</button>"+
                      "</div>"+
                      "</form>"+
                    "</div>"
                }     
              }

This is how I have written the ajax

$("#contactForm").on('submit',function(e){

        e.preventDefault();

        var Feedback = $("input[name=title]").val();
        var url = '{{ route('postinsert') }}';
        
        $.ajax({
           url:url,
           method:'POST',
           data:{
                  
                  Feedback:Feedback
                },
           success:function(response){
              if(response.success){
                  alert(response.message) //Message come from controller
              }else{
                  alert("Error")
              }
           },
           error:function(error){
              console.log(error)
           }
        });

and this is my controller code:

 public function ajaxRequestPost(Request $request)
    {

        \DB::table('memberdetails')->insert([
            'Feedback' => $request->Feedback, //This Code coming from ajax request
        ]);

        return response()->json(
            [
                'success' => true,
                'message' => 'Data inserted successfully'
            ]
        );
    }

As I am working on this for the first time not sure how I can achieve my desired output, any help to resolve would be really great.

over 4 years ago · Santiago Trujillo
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