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条)

报告相同问题?

悬赏问题

  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历