How to use AJAX to return a variable in PHP? I am currently using echo in my controller to display the price of a dropdown .change at a div price.
However, I have a hidden field in which I need to return the row identifier for the change. How to assign return var in jQuery so that I can repeat it in my hidden field?
JQuery
$(document).ready(function() { $('#pricingEngine').change(function() { var query = $("#pricingEngine").serialize(); $('#price').fadeOut(500).addClass('ajax-loading'); $.ajax({ type: "POST", url: "store/PricingEngine", data: query, success: function(data) { $('#price').removeClass('ajax-loading').html('$' + data).fadeIn(500); } }); return false; }); });
Controller
function PricingEngine() { //print_r($_POST); $this->load->model('M_Pricing'); $post_options = array( 'X_SIZE' => $this->input->post('X_SIZE'), 'X_PAPER' => $this->input->post('X_PAPER'), 'X_COLOR' => $this->input->post('X_COLOR'), 'X_QTY' => $this->input->post('X_QTY'), 'O_RC' => $this->input->post('O_RC') ); $data = $this->M_Pricing->ajax_price_engine($post_options); foreach($data as $pData) { echo number_format($pData->F_PRICE / 1000,2); return $ProductById = $pData->businesscards_id; } }
View
Here is my hidden field. I want to pass the var every time the form changes. "/">
Thanks for the help!
fyz
source share