DragonWar% 2017-07-03 11:51 采纳率: 0%
浏览 21

jQuery Ajax值获取

I want to fetch value through jquery Ajax in PHP. but when I run below this code value is fetch properly but all value are joined together when fetching and together value print all field, but I want to print the separate value in the separate field. my code is below, please solve this problem

index.php

<!DOCTYPE html> 
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<select name="Pro" onChange="my_validate_func()" id="pro_serv">
<option value=""></option>
<option value="" ><font size="-1">Add New Product</font></option>
<option value="Development"><font size="-1">Development</font></option>
<option value="Maintance"><font size="-1">Maintance</font></option>
</select>
<br />
<input type="text" name="desc" id="desc" value="" />
<br />
<input type="text" name="unitprice" id="unitprice" value="" />
<br /><input type="text" name="discount" />
<script type="text/javascript" src="bootstrap/jquery1.8.3jquery.min.js">
</script>
<script>
$( document ).ready(function() {});
function my_validate_func() {
var pro_serv = $('#pro_serv').val();

    if ($('#pro_serv').val() != "" ) {
        $.ajax({
            type: "POST",
            url: 'check.php',
            data: { pro_serv: pro_serv},
            success: function(response) {
                $('#desc').val(response);
                $('#unitprice').val(response);
                $('#tax').val(response);

            }

        });
    }
    }
</script>
</body>
</html>

check.php

<?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;
}


?>
  • 写回答

3条回答 默认 最新

  • weixin_33722405 2017-07-03 11:59
    关注

    You can use a separates for separate values then use JS split function.

     echo $desc ."-" . $unitprice ."-" .$tax;
    

    In Js

    var arr = response.split('-');
    $('#desc').val(arr[0]);
    $('#unitprice').val(arr[1]);
    $('#tax').val(arr[2]);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭