JQuery Post: Adding Publish Data

I am using jQuery 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);
});

He publishes a choice made in the form. Is it possible to add data to the message. Thus, in addition to the form data, I need to add a pair of lat longs to the jQuery post. How should I do it. Is it possible?

You know.

-Laxmidi

+5
source share
2 answers

.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);
});

Be careful; the string must be correctly formatted as a url, so you need pairs key=valueseparated by &s.

+ "&foo=bar. & , .serialize(), foo= - , bar - .

, - :

&foo=bar&baz=zip
+6
var thename = jQuery("input#name").val();
var data = {'anycolortoulike':'transparent'}; // any data;
jQuery.post(the_ajax_script.ajaxurl, data.concat(jQuery("#theForm").serializeArray()),
    function(response_from_the_action_function){
       jQuery("#response_area").html(response_from_the_action_function);
    }
);

, $.post

0

All Articles