Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
Laravel 8 AJAX Crud - How to send JS variables in the data field

Hi I am a beginner to Laravel and AJAX programming, and I am trying to send a JavaScript variable through the data field

Here is my code:

        $.ajax({
                type: "post",
                url: "/checklists/" + checkButtonId,
                data: {relevantClasses : JSON.stringify(relevantClasses)},
                dataType: "json",
                success: function (response) {
                    if(response.success) {
                        $(taskId).removeClass(relevantClasses);

                        alert(JSON.stringify(response.checked + " " + response.request + " " + response.id));

                        switch(response.checked) {
                            case 0:
                            $(taskId).addClass("far fa-square");
                            break;

                            case 1:
                            $(taskId).addClass("fas fa-check-square");
                            break;
                        }
                    }
                }
            });

The variable relevantClasses is a JavaScript let variable. I tried to stringify it with JSON and it returns in the alert, but in the Controller I can't compare this variable with a PHP one. (I used json_decode() function and nothing happens)

can you please help me?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you could send relevantClasses like this

        $.ajax({
                type: "post",
                url: "/checklists/" + checkButtonId,
                data: {
                    'relevantClasses' : JSON.stringify(relevantClasses)
                },
                dataType: "json",
                success: function (response) {
                    if(response.success) {
                        $(taskId).removeClass(relevantClasses);

                        alert(JSON.stringify(response.checked + " " + response.request + " " + response.id));

                        switch(response.checked) {
                            case 0:
                            $(taskId).addClass("far fa-square");
                            break;

                            case 1:
                            $(taskId).addClass("fas fa-check-square");
                            break;
                        }
                    }
                }
            });

if it didn't work please upload your controller

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!