1

ここにアラート用の私の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" divを見ることはできますがビューソースのタグ、何が間違っているのですか?

必要 - 応答に基づいて、テキストに適切なアラートを自動的に挿入したい

私はjQueryを学んでおり、これにはエラーがあると確信していますが、これがどこで失敗しているのか理解できません

4

1 に答える 1

0

関数にいくつかのエラーがあります。ajax関数をsuccessオブジェクト内に配置し、 を逃しました)。次のことを試してください。

    $.ajax({
        type: 'POST',
        url: 'addVideo',
        data: {
            video_title: title,
            playlist_name: playlist,
            url: id },
        success: notify('success', 'saved!'),
        error: notify('failure', 'not saved!')
        })
于 2012-08-06T20:15:03.740 に答える