以下代码中的$ .post不起作用?

时间:2014-03-15 10:45:13

标签: javascript php jquery ajax

函数updateTtotal()用于表中的Autosum生成。

 function updateTtotal(element) {     
 var form = element.form;
 var num = element.name.replace(/^\D+/,'');
 var value = parseFloat(form['value' + num].value) + parseFloat(form['tax_amount' + num].value);
 form['total' + num].value =  (value == 0)? '0' : value;
updateGtotal(form);
 }
 function updateGtotal(form) {
 var elements = form.elements;
 var name = /^total/;
 var total = 0;
 var value;
var flag =0;
 for (var i=0, iLen=elements.length; i<iLen; i++) {
   if ((name.test(elements[i].name))&&(elements[i].value!=0)) {
    total += parseFloat(elements[i].value);
   }
 }
 form.g_total.value = total;
 var val = total;
 $.post( "numconv.php", { amount: val})// This Code generates no error but does not work
    .done(function( data ) {
            form.g_total_word.value = data;
    });
 }

numconv.php如下所示。(这在成功执行时工作正常)

<?php 
require_once("include/currency_class.php");
$var = new CurrencyToWords();
$amt = floatval($_POST['amount']);
$result = $var->translateInWords($amt);
echo $result;
?>

1 个答案:

答案 0 :(得分:0)

尝试将$ post功能更改为此 - 可能有助于查看问题所在:

$.post("numconv.php", {
amount: val
 })
.success(function(data){    
 //some code on data return if you want
  alert(data + " success function");
})
.done(function(data){
  alert(data + " done function");
})
.fail(function(jqXHR, textStatus, errorThrown){
  alert("Unable to retrieve data from the server, error code:" + errorThrown);
});

希望它有所帮助。