Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

279
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda