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 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误