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

278
Views
saving javascript variables from laravel blade.php to database

I am developing a product pricing calculator in laravel. Inside the <script> tag of blade.php i have some javascript variables like,

<script>
.........
front-end logics
.........
var country;
var product_type;
var product_link ;
var seller_shipping_fee;
var weight;
var dimensions;
........
........
</script>

I want to store those variables in the database. I have already created the table in database using laravel migration.

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePriceCalculatorResponsesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::connection('pgsql')->create('price_calculator__responses', function (Blueprint $table) {
            $table->increments('id');
            $table->string('country');
            $table->string('product_type');
            $table->string('product_link');
            $table->string('seller_shipping_fee');
            $table->string('weight');
            $table->string('dimension');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::connection('pgsql')->dropIfExists('price_calculator__responses');
    }
}

How do I save those Javascipt variables in the database?

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

0

    <script>
    
      $(".save-data").click(function(event){
          event.preventDefault();
    
          let country = $("input[name=country]").val();
          let product_type = $("input[name=product_type]").val();
          let product_link = $("input[name=product_link]").val();
          let seller_shipping_fee = $("input[name=seller_shipping_fee]").val();
          ...............more variables..............
    
          $.ajax({
            url: "/ajax-request",
            type:"POST",
            data:{
              country:country,
              product_type:product_type,
              _token: _token,
................. more variables....................
            },
            success:function(response){
              console.log(response);
              if(response) {
                $('.success').text(response.success);
                $("#ajaxform")[0].reset();
              }
            },
            error: function(error) {
             console.log(error);
            }
           });
      });
    </script>

Something like that to put your on the right track, do not forget to have your input id match with yur variables if sending data is secure do not forget the token variale it is usually hidden input on symfony i dont know if it is the same case in Laravel. include ajax cdn too :)

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!