doufocheng6233 2014-03-21 18:51
浏览 53
已采纳

单击bootstrap选项卡时运行jquery函数

I want to run an ajax function when I click on bootstrap tab.

I have html:

  <li><a href="#upotrebljeni" data-toggle="tab">Upotrebljeni resursi</a></li>

jquery ajax function:

$('a #upotrebljeni').click(function (e) {
var ajdi = '22';
var radnici = 'radnici';
var prvi = '1'; 
    $.ajax({
            url: 'getRMZ.php', // make this url point to the data file
            dataType: 'json',
            data:{id_akt:ajdi, tabela:radnici, prvi:prvi},
            async: false,
        type: 'POST',
            success:function(data){
            console.log(data);
            },
        error:function(data) {
        console.log(data);
        }

        });

});

and getRMZ.php pdo file:

try {
      /* Establish the database connection */
      $conn = new PDO("mysql:host=localhost;dbname=$dbname", $username, $password);
      $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

     $result = $conn->query("SELECT id_tabele,naziv FROM track_aktivnosti WHERE prvi = :prvi AND id_akt = :id_akt AND tabela = :tabela");
     $result->execute(array(':prvi' => $_POST['prvi'], ':id_akt' => $_POST['id_akt'], ':tabela' => $_POST['tabela']));

    $jsonTable = json_encode($result);
    } catch(PDOException $e) {
        echo 'ERROR: ' . $e->getMessage();
    }
    echo $jsonTable;

Now when I click on tab a #upotrebljeni I dont get any action, any error, nothing ... What can be a problem here?

UPDATE: I via ajax get an error: "ERROR: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':prvi AND id_akt = :id_akt AND tabela = :tabela' at line 1"

  • 写回答

2条回答 默认 最新

  • dqybeh2884 2014-03-21 18:55
    关注

    You need to add id="upotrebljeni" to your anchor:

    <li><a id="upotrebljeni" href="#upotrebljeni" data-toggle="tab">Upotrebljeni resursi</a></li>
    

    since you're using # so it'll target element by id not href.

    Also, because id is unique, you just need to use:

    $('#upotrebljeni').click(function (e) {
    

    instead of:

    $('a#upotrebljeni').click(function (e) {
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器