从AJAX获取数据 - 如何 [英] Get data from AJAX - How to
问题描述
我有一个脚本,它从两个选择标记中获取值,然后执行一个简单的数学运算来计算价格。我需要的东西,但无法弄清楚的是,如何获得 计算的价格,并将其用作POST表格中的php变量。
I have a script, that takes the value from two select tags, and then do a simple math multipy to calculate a price. The thing I need, but cannot figure out is, how to get that calculated price, and use it as an php variable in a POST form.
由于计算出的价格是动态的,我该如何归档?
As the calculated price is dynamic, how can I archive this?
推荐答案
如果要将该值直接发送给a PHP脚本,你可以使用jQuery post
方法:
If you want to send that value directly to a PHP script, you can use the jQuery post
method:
$.post("yourScript.php", { price: yourPriceVar }, function(data) {
//Success! Do something interesting
});
或者,您可以设置值
计算值的隐藏输入元素,以便可以与表单的其余部分一起提交:
Alternatively, you could set the value
of a hidden input element to your calculated value, so that it can be submitted along with the rest of your form:
$("#hiddenInput").val(yourPriceVar);
HTML:
<input type="hidden" id="hiddenInput" name="price" />
这篇关于从AJAX获取数据 - 如何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!