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

171
Vistas
Previous and Next month from button change in php

So I have a prev and next month button and on.click events for ajax call. My reference is just a month in string for my example 'April'.

Sample button event for 'next' button,

$(document).on('click', '.events-next', function() {
    var $el = $(this);
    var action = $el.attr('data-action');
    var $month = $('.events-month-option').text();

    $.ajax({
        method: 'post',
        url: path+'js/ajax/get-events.php',
        data: {
            'current_month': $month,
            'action': action,
            'xid': c_xid
        },
        dataType: 'json'

    }).done(function(data){

        console.log(data);

    }).fail(function(data){
        dialogAlert('Error', 'Unable to retrieve events.', 'error');
    });
});

and my Ajax file

$response = array();
$current_month = ($_POST['current_month'] ?? NULL);
$month = date('m', strtotime($current_month));

$action = ($_POST['action'] ?? NULL);

if($action == 'next'){
    $new_period = date('m', strtotime($month.' +1 month'));
} 

$response['new_month'] = $new_period;
$response['action'] = $action;

Why I'm getting a value of 12? instead 05 for May? And after I click my button again it doesn't update anymore.

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