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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀