普通网友 2016-12-07 10:48
浏览 29

返回数据AJAX PHP

By defaut, when my system loads some data is filtered in my db and shown to the user. But my doubt is how can I call AJAX to filter some new data, and return it, changing the default values that are already set on my variables.

This is my AJAX call:

 $("#botao-filtrar").click(function(){
  $(".mask-loading").fadeToggle(1000);
  $.ajax({
    url: 'datacenter/functions/filtraDashboardGeral.php',
    type: 'POST',
    data: {rede: $("#dropdown-parceria").val()},
  })
  .done(function(resposta){
    console.log(resposta);
  })
  .always(function(){
    $(".mask-loading").fadeToggle(1000);
  })
});

And this is what I got from trying to filter some data to return it, but nothing worked:

<?php
    require_once('../../includes/conecta.php');

    $rede = $_POST['rede'];

    function buscaDados($conexao){
        $dados = array();

        $resultado = mysqli_query($conexao, "SELECT * FROM evolucao_originacao WHERE rede = {$rede}");

        while($valores = mysqli_fetch_assoc($resultado)){
            array_push($dados, $valores);
        }
    }

Any idea?

Thanks!

  • 写回答

2条回答 默认 最新

  • weixin_33749131 2016-12-07 10:51
    关注

    You should add echo at the end :

    echo json_encode($dados);
    

    So the $dados array will be sent back to the ajax request as JSON response.

    Parse the response to json uisng $.parseJSON() :

    .done(function(resposta){
         resposta = $.parseJSON(resposta);
    
         console.log(resposta);
    })
    

    Hope this helps.

    评论

报告相同问题?

悬赏问题

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