php - Jquery variable returns null -


i working on wordpress shop right , trying implement currency converter. in cart table dropdown list of available currencies.

when clicked price should show in currency. simple enough...

here part of php list:

<section class="currency-converter-form" style="display:none;">          <p class="form-row form-row-wide" id="convert_to_field">         <select name="currency" id="currency" class="currency_to" rel="convert_currency_to" >             <option value="gbp" >gbp - british pound sterling</option>             <option value="usd" >usd - dollar</option>             <option value="aud" >aud - australian dollar</option>             <option value="cad" >cad - canadian dollar</option>             <option value="jpy" >jpy - japanese yen</option>             <option value="nzd" >nzd - new zealand dollar</option>             <option value="rub" >rub - russian ruble</option>             <option value="chf" >chf - swiss franc</option>         </select>         </p> 

here have jquery far:

jquery( function( $ ) {  $( document ).on( 'click', '.currency-converter-button', function() {     $( '.currency-converter-form' ).slidetoggle( 'slow' );       return false; }).on( 'change', function() {      var currency = $( "#currency" ).val();      console.log(currency);      jquery.ajax({     type: 'post',     url: currency_conversion.ajaxurl,     data: {         action: 'get_conversion',         currency     },     success: function (data, textstatus, xmlhttprequest) {         alert(data);     },     error: function (xmlhttprequest, textstatus, errorthrown) {         alert(errorthrown);     } });      });$( '.currency-converter-form' ).hide(); }); 

here target php test thing:

    add_action( 'wp_ajax_get_conversion', 'get_conversion' );    function get_conversion() {   $to = $_post['currency'];   echo json_encode($to);} 

i tried use code existing in wordpress adjusted it. happy if alert give me selcted currency, returns 0.

i googled lot , tried different things no avail. appriciate here.

i'm not sure if problem in code, it's one: currency value inside data passed php has no key. correct data pass be:

data: {     action: 'get_conversion',     currency: currency }, 

with this, php should able access $_post['currency'] currency value unless there other problems.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -