UzumakiDev
UzumakiDev

Reputation: 1276

sending variable through ajax post?

I'm doing some ajax stuff which triggers on a click event, the link has a couple of values and variables.

The link in question looks like this:

<?php $link_url = esc_url(wp_nonce_url( site_url('?my_page=ajax-processor&action=dynamic_date_loop&my_date='.$date), 
"dynamic_date_loop_nonce") ); ?>

The $date variable above holds a string like "2013-09".

I process this link and extract the values here:

var url = wpAjax.unserialize(element.attr('href'));
var s = {};
s.data = $.extend(s.data, { action: url.action, _ajax_nonce: url._wpnonce });

I understand the syntax for this goes something like var1:value1 but here my value is a variable, so in this context do I just add my_date: url.$date ? This just doesn't look right to me.

Upvotes: 0

Views: 83

Answers (2)

Barmar
Barmar

Reputation: 780723

I think this is what you want:

s.data = $.extend(s.data, {
    action: url.action,
    _ajax_nonce: url._wpnonce,
    my_date: url.my_date 
});

Upvotes: 1

Moeed Farooqui
Moeed Farooqui

Reputation: 3622

No you need to store the value in javascript variable

var a = '<?php echo $date; ?>';

Now variable a contains the value of $date. Now you can do whatever you want with a. Check it by alerting alert(a);

Upvotes: 0

Related Questions