Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.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值获取中的Jquery ajax_Php_Jquery_Ajax - Fatal编程技术网

php值获取中的Jquery ajax

php值获取中的Jquery ajax,php,jquery,ajax,Php,Jquery,Ajax,我试图在php中使用jQueryAjax从数据库中获取值。当我运行并从产品/服务中选择“开发”时,值获取但所有获取值都连接在一起,joinvalue显示所有字段。但我想在不同字段中显示不同的值。如何解决这个问题。我的代码如下。请检查并解决这个问题 index.php check.php 使用 返回JSON格式的Ajax响应 <script> $(document).ready(function () {}); function my_validate_func() {

我试图在php中使用jQueryAjax从数据库中获取值。当我运行并从产品/服务中选择“开发”时,值获取但所有获取值都连接在一起,joinvalue显示所有字段。但我想在不同字段中显示不同的值。如何解决这个问题。我的代码如下。请检查并解决这个问题

index.php

check.php

使用

返回JSON格式的Ajax响应

<script>
    $(document).ready(function () {});
    function my_validate_func() {
      var pro_serv = $('#pro_serv').val();
      if ($('#type').val() != "") {
        $.ajax({
            type: "POST",
            url: 'check.php',
            data: {pro_serv: pro_serv},
            dataType: "json", //Newly Added
            success: function (response) {
              if(response.length != 0){ //Newly Added (Check, if array is not empty, then print the returned values to respective fields)
                $('#desc').val(response['desc']); //Modified
                $('#unitprice').val(response['unitprice']); //Modified
                $('#tax').val(response['tax']); //Modified
              }
            }
        });
      }
    }
  </script>
check.php


然后学习什么是json。在check.php中,编写print\r$return\u值;死亡在返回json_之前编码$return_值;并检查@DoniNo value的值:如果我运行directcheck.php。第6行中的show parser error表示$return_values=[];
<?php
include('database/db.php');
$type=$_POST['pro_serv'];
$sql="Select * from product_service_details where type='$type'";
$result=mysql_query($sql);
if($dtset=mysql_fetch_array($result)) {
  $desc=$dtset['desc'];
  $unitprice=$dtset['unitprice'];
  $tax=$dtset['tax'];
  echo $desc;
  echo $unitprice;
  echo $tax;
}?>
<script>
    $(document).ready(function () {});
    function my_validate_func() {
      var pro_serv = $('#pro_serv').val();
      if ($('#type').val() != "") {
        $.ajax({
            type: "POST",
            url: 'check.php',
            data: {pro_serv: pro_serv},
            dataType: "json", //Newly Added
            success: function (response) {
              if(response.length != 0){ //Newly Added (Check, if array is not empty, then print the returned values to respective fields)
                $('#desc').val(response['desc']); //Modified
                $('#unitprice').val(response['unitprice']); //Modified
                $('#tax').val(response['tax']); //Modified
              }
            }
        });
      }
    }
  </script>
<?php
include('database/db.php');
$type=$_POST['pro_serv'];
$sql="Select * from product_service_details where type='$type'";
$result=mysql_query($sql);
$return_values = []; //Newly Added
if($dtset = mysql_fetch_array($result)) {
  /* Modified */
  $return_values = [
    'desc' => $dtset['desc'],
    'unitprice' => $dtset['unitprice'],
    'tax' => $dtset['tax']
  ];
}
return json_encode($return_values); // Return as JSON format
?>