【问题标题】:Can't use jquery ajax to reorder a list无法使用 jquery ajax 重新排序列表
【发布时间】:2013-11-19 20:33:37
【问题描述】:

我正在使用 jquery ajax 加载一个新的 php 查询,其中列表顺序已更改。但由于某种原因,什么都没有发生。这是我正在使用的查询(load.php):

$stm = $conn->prepare('SELECT projetos.projeto FROM projetos ORDER BY projetos.projeto DESC');
$stm->execute();

$result = $stmt->fetchAll(PDO::FETCH_OBJ);

echo json_encode($result);

这是 jquery 的摘录:

$('.chosen-select').change( function(){

$.ajax({
    type: 'POST',  
    dataType: 'json',
    url: 'php/load.php',
    success: function(data) {
        for(var i = 0; i < data.length; i++){
          $('#project-grid').append(data[i].projeto)
        }
   } 
});

});

【问题讨论】:

  • 您在成功函数中使用 console.log(data) 时看到了什么?
  • @meavo 我添加了一个错误函数并返回以下内容: Undefined variable: stmt in ...load.php on line 9
  • 在浏览器控制台/开发者工具的网络选项卡中检查请求以获取线索...可以查看发送的内容、返回的内容、状态等
  • 愚蠢的错误:$stm 和 $stmt。对不起,伙计们。
  • @user3004794 我只是建议你可能在某处有错字,哈哈 :)

标签: php jquery mysql ajax


【解决方案1】:

尝试发送 GET 请求而不是 POST:

$.get('php/load.php', function (data) 
{
   for(var i = 0; i < data.length; i++)
   {
    $('#project-grid').append(data[i].projeto)
   }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-06
    • 1970-01-01
    • 1970-01-01
    • 2017-04-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多