Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我从php得到响应,但没有在文本框中打印_Php_Jquery - Fatal编程技术网

我从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

我有两个文件,一个用于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").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(数据)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