I'm using jQuery's post on a WordPress page.
var thename = jQuery("input#name").val();
jQuery.post(the_ajax_script.ajaxurl, jQuery("#theForm").serialize(),
function(response_from_the_action_function){
jQuery("#response_area").html(response_from_the_action_function);
});
It posts the selections made in a form. Is it possible to append data to a post. So in addition to the form data, I need a couple lat longs added to the jQuery post. How can I do that. Is it possible?
Thnak you.
-Laxmidi
.post()
takes a string as the second argument, so you can concatenate a custom string using +
followed by your string.
var thename = jQuery("input#name").val();
jQuery.post(the_ajax_script.ajaxurl, jQuery("#theForm").serialize() + "&foo=bar",
function(response_from_the_action_function){
jQuery("#response_area").html(response_from_the_action_function);
});
Do be careful, though; the string has to be correctly formatted as a URL, so you need key=value
pairs separated by &
s.
In the example above, you'll see + "&foo=bar
. The first &
finishes the last value created by .serialize()
, then foo=
is a key, followed by bar
as the value.
If you want to add more values afterwards, you can do something like this:
&foo=bar&baz=zip
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With