我从php得到响应,但没有在文本框中打印
我有两个文件,一个用于HTML和jQuery,另一个用于PHP。我从php得到响应,但没有在文本框中打印,php,jquery,Php,Jquery,我有两个文件,一个用于HTML和jQuery,另一个用于PHP。 我从PHP页面得到响应,但我无法在HTML文本框中显示 这是我的密码: <script type="text/javascript"> function fill_amt() { var sname=$("#sname").val(); $.post("try_insert.php",{sname:sname,cmd2:"fill_amt"},function(data){ $("#tot_amt").ht
我从PHP页面得到响应,但我无法在HTML文本框中显示 这是我的密码:
<script type="text/javascript">
function fill_amt()
{
var sname=$("#sname").val();
$.post("try_insert.php",{sname:sname,cmd2:"fill_amt"},function(data){
$("#tot_amt").html(data);
});
}
</script>
使用:
$(“总金额”).val(数据)代码>
而不是
$(“tot#u amt”).html(数据)代码>
还应正确格式化json数据。您的JS代码应
<script type="text/javascript">
function fill_amt()
{
var sname=$("#sname").val();
$.post("try_insert.php",{sname:sname,cmd2:"fill_amt"},function(data){
var json=JSON.parse(data); // parsing data form JSON string and convert it into object
$("#tot_amt").val(json.total);
});
}
</script>
$sql = mysql_query("select total_fee from admission where first_name='".$sname."'")or die(mysql_query());
$val=mysql_fetch_assoc($sql);
$tot=$val['total'];
echo json_encode(array("total"=>$tot)); // give response as json string
使用$(“#tot_amt”).val(数据)
而不是$(“#tot_amt”).html(数据)你能解释一下解决方案吗?错误在哪里?因此OP可以理解您修复的内容。您也可以将dataType
设置为json
,并自动对其进行解析。@MarcGiroux感谢您的工作,但它将在中以双倒逗号显示textbox@NehaSutariya您需要正确解析jsondata@NehaSutariya“双倒逗号”?你是说报价吗?
<script type="text/javascript">
function fill_amt()
{
var sname=$("#sname").val();
$.post("try_insert.php",{sname:sname,cmd2:"fill_amt"},function(data){
var json=JSON.parse(data); // parsing data form JSON string and convert it into object
$("#tot_amt").val(json.total);
});
}
</script>
$sql = mysql_query("select total_fee from admission where first_name='".$sname."'")or die(mysql_query());
$val=mysql_fetch_assoc($sql);
$tot=$val['total'];
echo json_encode(array("total"=>$tot)); // give response as json string