【问题标题】:PHP/AJAX stored procedure issuePHP/AJAX 存储过程问题
【发布时间】:2014-04-24 03:09:30
【问题描述】:

我遇到了通过选择更改事件启动的存储过程的问题。我的问题是,即使我能够获取所选项目的值,当我将它作为参数传递给存储过程并绑定它时,该过程也不会启动。我尝试静态启动它并且它可以工作。 我已经尝试更改 dataType 和 Mime Type 以及其他内容,但我被卡住了。 代码如下:

$groupe = new Groupe();

if (isset($_POST['value'])){

    $param = $_POST['name'];

    $storedProcedure = 'Call listeTitresParGroupe(:groupes)';

    $query = $groupe->prepare($storedProcedure);
    $query->bindParam(':groupes', $param, PDO::PARAM_STR);


    $query->execute();

    echo $_POST['name'].' -> '.$param.'   '.$storedProcedure;
    echo '<table class="table table-hover col-lg-12">';

    while ($resultat = $query->fetch()){

        echo'<tr><td class="col-md-12">'.$resultat[0].'</td></tr>';

    }
    echo '</table>';
} 

AJAX 代码:

var selectedText = {value: $('#groupe option:selected').text(),  name:$('#groupe option:selected').text()};

    $.ajax({

        url: './storedProcedures.php',
        type: 'POST',
        dataType: 'text',
        mimeType : 'text/html; charset=UTF-8',
        data: selectedText

    })
    .done(function(data){$('#titres').html(data);})
    .fail(function() {

        console.log("Erreur");
        alert('AJAX query has failed');

    })
    .always(function() {

        console.log("Terminé");

    });

如果有人知道为什么它不起作用,我将非常感激

【问题讨论】:

  • ajax 中没有存储过程。选择一个您正在使用的领域

标签: ajax stored-procedures pdo


【解决方案1】:

只是为了换一种方式尝试,你可以尝试移除绑定:

$query->bindParam(':groupes', $param, PDO::PARAM_STR);

并尝试将您的参数放在执行函数中:

$query->execute(array(':groupes'=>$param));

这是少了一行代码,值得一试,也许只是看看它是否也会失败。

【讨论】:

  • MinnesotaSlim 感谢您的回答,我已经尝试过您的解决方案,但仍然无法正常工作,有人知道吗?在我看来,问题确实是由于参数绑定失败...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-17
  • 2020-08-03
相关资源
最近更新 更多