FFSS
FFSS

Reputation: 133

jquery ajax not sending dates

I am hoping someone can help me with this problem I am facing:

I have an ajax call as follow:

$(document).ready(function(){  
    $("#booking").submit(function() {
        var arrival   = $('#arrival').attr('value');
        var departure = $('#departure').attr('value');
        var ap_ID     = $('#ap_ID').attr('value');

        $.ajax({
          type: "POST",
          url: "ajax/val_booking.php",
          data: "arrival="+ arrival +"&departure="+ departure +"&ap_ID=" + ap_ID,
        });

        return false;
    });
});

All the fields in the html form have a "name" attribute.

When sending info the ap_ID is sent but the arrival and departure are empty (checked with Firebug).

Also used serialize() but same result.

Does anyone know where might be the problem or what I might be doing wrong?

Thank you everybody for your help.

PS: I am using datepicker

Upvotes: 1

Views: 125

Answers (2)

nolabel
nolabel

Reputation: 1157

You have a comma at the end of "data: "arrival="+ arrival +"&departure="+ departure +"&ap_ID=" + ap_ID,"

Remove the comma and you should be good.

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1038730

Try like this:

$('#booking').submit(function() {  
    var arrival = $('#arrival').val()  
    var departure = $('#departure').val();  
    var ap_ID = $('#ap_ID').val(); 
    $.ajax({  
        type: 'POST',  
        url: 'ajax/val_booking.php',  
        data: { 
            arrival: arrival, 
            departure: departure, 
            ap_ID: ap_ID 
        },
        success: function(result) {
            alert('success');
        }
    });  
    return false;  
});

or if you want to send all form values you could use the .serialize() function:

$('#booking').submit(function() {  
    $.ajax({  
        type: 'POST',  
        url: 'ajax/val_booking.php',  
        data: $(this).serialize(),
        success: function(result) {
            alert('success');
        }
    });  
    return false;  
});

Upvotes: 1

Related Questions