jQuery,Twitter引导程序:如何基于操作生成警报(和文本)? [英] jQuery, Twitter bootstrap: How do I generate alerts(and text) on based on actions?

查看:49
本文介绍了jQuery,Twitter引导程序:如何基于操作生成警报(和文本)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的HTML警报

<div id="feature" class="feature">
    <div id="alerts">
    </div>
    # other html data
</div>

这是我的Ajax通话

        // send the data to the server using .ajax() or .post()
        $.ajax({
            type: 'POST',
            url: 'addVideo',
            data: {
                video_title: title,
                playlist_name: playlist,
                url: id,
                success: notify('success', 'saved!')
                error: notify('failure', 'not saved!')
            },

这是notify函数的外观

function notify(notify_type, msg) {
    var alerts = $('#alerts');
    alerts.append('<a class="close" data-dismiss="alert" href="#">×</a>');
    if (notify_type == 'success') {
      alerts.addClass('alert alerts-success').fadeIn('fast');
    }
    if (notify_type == 'failure') {
      alerts.addClass('alert alerts-error').fadeIn('fast');
    }
}

我在这里使用参考- http://twitter.github.com/bootstrap/components.html#alerts 在Firebug上调试时,我看到在选择器"#alerts"中未找到任何元素 尽管我可以在view-source中看到div标签,但一定有什么问题吗?

I am using reference from here - http://twitter.github.com/bootstrap/components.html#alerts When I debug on Firebug, I see No elements were found with the selector: "#alerts" Although I can see the div tag in view-source, what must be wrong?

需要 -根据回复,我想在文本中自动插入适当的提醒

Needed - Based on response I would like to insert appropriate alert in text automatically

我正在学习jQuery,我确定这有错误,但是无法理解失败的地方

I am learning jQuery and I am sure this has error, but not able to understand where this is failing

推荐答案

您的ajax函数存在一些错误,您已将success函数放在对象中并错过了),请尝试以下操作:

There are some errors in your ajax function, you have put the success function within the object and missed a ), try the following:

    $.ajax({
        type: 'POST',
        url: 'addVideo',
        data: {
            video_title: title,
            playlist_name: playlist,
            url: id },
        success: notify('success', 'saved!'),
        error: notify('failure', 'not saved!')
        })

这篇关于jQuery,Twitter引导程序:如何基于操作生成警报(和文本)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆