javascript - How to pass many ajax results to different input values? -
my ajax return results 4 values.i want assign these values 4 input value.here ajax code:
$.ajax({ type:"post", url:"modify_cbndtb.php", data: {cabinetnum:id}, success:function (res) { } });
modify_cbndtb.php code:
if(isset($_post['cabinetnum'])) { $q=$_post["cabinetnum"]; $sql="select num1,num2,num3,num4 hpc sysid= '".$q."';"; $sel = $conn->query($sql); }
my html code:
<div id="content" class="content"> 1u:<input type="text" id="1u" value="">11u:<input type="text" id="11u" value=""><br /> 2u:<input type="text" id="2u" value="">12u:<input type="text" id="12u" value=""><br /> </div>
1u.value should num1. 2u.value should num2. 3u.value should num3. 4u.value should num4. don't know how realize. can me?
i think can try this
modify_cbndtb.php if(isset($_post['cabinetnum'])) { $q=$_post["cabinetnum"]; $sql="select num1,num2,num3,num4 hpc sysid= '".$q."';"; $sel = $conn->query($sql); $arr = $sel->fetch(pdo::fetch_assoc); $data = json_encode($arr); echo $data; }
and ajax
client file $.ajax({ type:"post", url:"modify_cbndtb.php", data: {cabinetnum:id}, success:function (data) { $('#1u').val(data[0].num1); $('#11u').val(data[0].num2); $('#2u').val(data[0].num3); $('#12u').val(data[0].num4); } });
i hope you
Comments
Post a Comment