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

84
Vistas
How to call variabled ajax

I put the ajax call in a variable, how can I call it again and pass some parameters to the data attribute of the ajax?.

var request = $.ajax({
    URL: '/usage_analytics.php',
    type: 'get',
    data: {date_start: dt_date_start, date_end: dt_date_end},
    dataType: 'json'
});

request.done(function (r) {
    console.log(r);
    //my codes goes here
});

now I have a date range picker, If i click apply button i just want to call the request variable to be able to trigger the ajax call again and pass some parameters.

$('#reportrange').on('apply.daterangepicker', function(ev, picker) {
    var picked_start = picker.startDate.format('YYYY-MM-DD');
    var picked_end   = picker.endDate.format('YYYY-MM-DD');

    dt_date_start = picked_start;
    dt_date_end   = picked_end;
    //call the request here and pass the dt_date_start and dt_date_end
});

TIA

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I don't think you can do that using a variable. I suggest you to define a function that contains your ajax request then you can call this function into your code like this:

function getUsageAnalytics(dt_date_start, dt_date_end) {
  return $.ajax({
    URL: '/usage_analytics.php',
    type: 'get',
    data: {date_start: dt_date_start, date_end: dt_date_end},
    dataType: 'json',
  });
});

After declaring your function you can use it like this:

$('#reportrange').on('apply.daterangepicker', function(ev, picker) {
  var picked_start = picker.startDate.format('YYYY-MM-DD');
  var picked_end   = picker.endDate.format('YYYY-MM-DD');

  getUsageAnalytics(picked_start, picked_end).done(function (r) {
    console.log(r);
    // your codes goes here
  });
});
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