I would like to retrieve selected value from dropdown and pass it using Yii’s ajaxLink function via POST method.
I can retrieve the values in the beforeSend part, for example,
array( // ajaxOptions
'type' => 'POST',
'beforeSend' => "function() {
start_time = jQuery('#start_time').find(':selected').val();
end_time = jQuery('#end_time').find(':selected').val();
this.data += '&start_time='+start_time;
this.data += '&end_time='+end_time;
}",
.......
I can format the string, pass it and parse it in the controller but I’m using protection from CSRF and if I pass parameters as a single string I get “CSRF token could not be verified” error.
Looking forward to your replies.
Put everything in a form and submit it (via an AJAX request) – then the form will POST it as usual, and you don’t have to munge any values. Alternatively, you could attach AJAX directly to the dropdown via htmlOptions, e.g.:
This way, the detail will get submitted via the form POST; you can do any munging you need in PHP after you’ve got the value submitted.
If you need a submit type item, I’d use an ajaxSubmitButton() instead of an ajaxLink(), and then you’re getting all the form data.