weixin_33697898 2017-12-13 20:50 采纳率: 0%
浏览 21

php与ajax集成

I have a record of carriers and clients. When selecting a carrier on the customer screen, I need it to be automatically filled out the carrier's e-mail and telephone. The PHP file is returning a JSON correctly, but it is dropping in the error of jquery and not in success. I checked in Firefox's Firebug and the HTML tab of the console, where the GET requisition is reset.

<?php
include "Config/config_sistema.php";
$res = mysql_query("SELECT * FROM transportadoras");
$menu_items = null;
while($ln = mysql_fetch_object($res)){
    $menu_items[] = $ln;
}
json_encode($menu_items);
?>
<script>
    $("body").on("change","#transportadoras",function(event){
        event.preventDefault();
        var trigger=$(this);
        $.ajax ({
            type: "POST",
            url: "buscaDadosTransportadora.php",
            dataType: 'json',
            success: function (data) {
                $("#telefone_transp").val(data.telefone);
                $("#email_transp").val(data.email);
            },
            error: function (data) {
                alert("Erro");
            },
        });
    });
</script>   

return in ajax

[{"ID":"5","Nome":"Vinicius","email":"viniciusbalbinot91@gmail.com","telefone":"32680018"},{"ID":"6","Nome":"teste","email":"teste@teste.com.br","telefone":"12345567"}]
  • 写回答

2条回答 默认 最新

  • Lotus@ 2017-12-13 21:41
    关注

    You response is array .

    [{"ID":"5","Nome":"Vinicius","email":"viniciusbalbinot91@gmail.com","telefone":"32680018"},....]
    

    you should loop through data.

     success: function (data) {
        $.each(data,function(user){ /* code ...*/});           
     }
    

    If you want some current row select one row from mysql .

    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号