dtol41388 2016-06-21 16:58
浏览 84

Jquery Ajax:尝试提取请求并将其输入到bootstrap轮播中

I am trying to pull ads into a bootstrap carousel on a chrome extension, first I got an error that said

bootstrap.min.js:6 Uncaught TypeError: Cannot read property 'offsetWidth' of undefined

I did some research and found the error was because I did not have the item active class and now I am trying to find a work around but cannot. I am trying to basically see if I can add a div after the one that contains the active. Here is my code and what I have tried...

main.js - variables and some functions have been taken out due to a large file

var myFuncs = { //Put in a class so I don't have to type it multiple times 
    ajaxRequest: function(target, method, url)
    {
        $.ajax({
            url: url,
            method: method,
            success: function(data) 
            {
                $(target).html(data).after(".item active");
            }
        });
    }
};

l1.addEventListener("mouseover", function() {
    l1.className = "active";
}, false);
l1.addEventListener("mouseout", function() {
    l1.className = ""; //Hackish but it works - class still appears but is not assigned 
}, false); //The other event listeners that do the same are taken out to avoid a long question they are all the same basically but l1 is changed to l2-l8

l1.addEventListener("click", function() {
    if (ajaxTarget[0].style.display === "none")
    {
        ajaxTarget[0].style.display = "block";
    }
    myFuncs.ajaxRequest(".b", "POST", ""); //Sensitive information taken out for stackoverflow question
}, false); Again l2-l8 was taken out to avoid a long question

I have no problems in the console.log. Here is my PHP...

<?php
    $servername = "";
    $username = "";
    $passcode = "";
    $dbname = "";

    $conn = mysqli_connect($servername, $username, $passcode, $dbname);

    if (!$conn)
    {
        echo 'Could not connect';
    }
    else 
    {
        try
        {
            $sql_query = mysqli_query($conn, "SELECT * FROM `adDatabase`");
            while ($row = mysqli_fetch_array($sql_query))
            {
                $id = $row['ID'];
                $img = $row['img'];
                $image = '<section class="item"><img src="data:image/png;base64,'.base64_encode( $row['food'] ).'" style="height: 12em; width: 12em; margin: 1em; padding: 0.9em; " ></section>';
                echo $image;
            }
        }
        catch(Exception $e)
        {
            echo $e;
        }
    }
?>

The images show up just fine in this PHP file, but when I try to load after the active class nothing shows up could I get some help on this?

  • 写回答

1条回答

  • duandaiqin6080 2016-06-21 17:19
    关注

    If you already have an active item, then you insert a new one after it you need to call $("#your-container").carousel("next"). Bootstrap will take care the rest thing(remove .active from current item and set .active to new item)

    评论

报告相同问题?

悬赏问题

  • ¥15 Java中消息和缓存如何使用
  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路