[英]how to display the json array value in html input
I am using the following jquery 我正在使用以下jQuery
<script type="text/javascript">
$(document).ready(function(){
$("#serviceId").change(function(){
var service_id=$("#serviceId").val();
$.ajax({
type:"post",
url:"<?php echo base_url();?>index.php/pranasInventory/get_service_amount",
data:{service_id:service_id},
success:function(data)
{
$('#amount').append(data);
},
});
});
});
</script>
I got the follwing responce in html input field 我在html输入栏中输入了以下响应
<input type="number" name="amount" id="amount" class="form-control" placeholder="Amount">[{"service_amount":"2000000"}]</input>
I want to display the service_amount in input value field.
please help me 请帮我
只需尝试:
$('#amount').val( data[0].service_amount );
Instead of append the data
object to input control, you should assign value to input control. 您应该将值分配给输入控件,而不是将data
对象附加到输入控件。 You can try any one code 您可以尝试任何一个代码
$('#amount').val(data[0].service_amount );
or 要么
$('#amount').val(data[0]["service_amount"]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.