1

I am passing data from a form through a normal AJAX call. What I need to do now is pass two additional variables through it elat and elng

What is the best method to include filter.serialize() and elat elng values through AJAX data?

    var elat = place.geometry.location.lat();
    var elng = place.geometry.location.lng();

    var filter = $('#filter');

    $.ajax({
        url: filter.attr('action'),
        data:filter.serialize(), //Pass [elat] and [elng] through here too.
        type: 'POST',
        dataType: 'json',
        success: function(response) {
        }
    });
2
  • what is #filter element? Commented Jul 29, 2017 at 15:44
  • @Ahmad it's input/select fields taken from a form. Wasn't sure if it's relevant for question. Commented Jul 29, 2017 at 15:49

1 Answer 1

2

You can manually concatenate to the string produced by filter.serialize()

data:filter.serialize() + '&elat=' + elat + '&elng=' + elng,

Or add hidden inputs to the form before serializing.

filter.append( $('<input>',{type:'hidden', name:'elat'}).val(elat));
filter.append( $('<input>',{type:'hidden', name:'elng'}).val(elng));
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect, went with the hidden input approach. Keeps it more organised! Thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.