在文本框中显示ajax结果

时间:2017-11-13 07:51:37

标签: javascript jquery ajax

从我的代码中,它在文本框中显示大厅输入类型标签 我只想显示值。

ajax功能:

function load_data(query)
 {
  $.ajax({
   url:"php_action/newfetchorder.php",
   method:"POST",
   data:{query:query},
   success:function(data)
   {

     $('#firstName').val(data);

   }

  });
 }

HTML:

<input  type="text" id="firstName" name="firstName"  /> 

PHP:

if(isset($_POST["query"])) {
    $search = mysqli_real_escape_string($connect, $_POST["query"]);
    $query = "
    SELECT * FROM product 
    WHERE Barcode LIKE '%".$search."%'
     ";

     $result1 = mysqli_query($connect, $query);
if(mysqli_num_rows($result1) > 0) {

  while($row = mysqli_fetch_array($result1)) {
     $output1 .= '<input type="text" name="item_name" value="'.$row["product_name"].'">';
     // $output2 .= '<input type="text" name="item_price" value="'.$row["Retail_price"].'">';
  }
  echo $output1;

}
else {
 echo 'Data Not Found';
}
}

输出:

enter image description here

预期产出:

enter image description here

2 个答案:

答案 0 :(得分:1)

$output1 .=$row["product_name"]而不是$output1 .= '<input type="text" name="item_name" value="'.$row["product_name"].'">';

$output1 variable and echo it的简单商店价值无需分配textbox here

答案 1 :(得分:-1)

更改此代码行

 $output1 .= '<input type="text" name="item_name" value="'.$row["product_name"].'">';

$output1 = $row["$product_name"];
相关问题