Почему этот условный диалог Ajax не работает?

Почему этот код не работает?

Тем временем (пытаясь заставить это работать) я изменил это время, но я не могу найти решение.

У кого-нибудь есть идея? У меня нет ошибок в консоли.

Прежде всего, он проверяет, нужно ли открывать диалог.

Это рабочий процесс:

Если DialogRequired => Dialog.Click = OK -> выполнить вызов ajax. Если DialogRequired => Dialog.Click = Cancel -> ничего не делать, если Dialog НЕ требуется => выполнить вызов ajax.

$(function () {
    $("a.orderlink").unbind();

    $("a.orderlink").bind("click", function () {
        var ProductID = $(this).parent().attr("data-productid");
        var Ammount = $(this).parent().parent().find("input#ammount").val();

        $.ajax({ type: "post",
            url: $(this).attr("href").replace("AddToCart", "ExistsInCart"),
            data: { ProductId: $(this).parent().attr("data-productid") },
            succes: function (data) {
                if (data == 1) {
                    $("#ProductExistsInOrder").dialog({
                        autoOpen: true,
                        height: 170,
                        width: 400,
                        modal: true,
                        buttons: {
                            "OK": function () {
                                /*acties om toe te voegen $.ajax()*/
                                $.ajax({ type: "post",
                                    url: $(this).attr("href"),
                                    data: { ProductId: ProductID, Ammount: Ammount },
                                    succes: function () {
                                        $("#AddProductNotification").text("U heeft net een product toegevoegd. Herlaad de pagina om uw winkelwagentje te bekijken");
                                    }
                                });
                                setTimeout("location.reload(true);", 100);
                                $(this).dialog("close");
                                location.reload(true);
                            //    return false;
                            },
                            "Annuleer": function () {
                                $(this).dialog("close");
                             //   return false;
                            }
                        }
                    });
                } else {
                    $.ajax({ type: "post",
                        url: $(this).attr("href"),
                        data: { ProductId: ProductID, Ammount: Ammount },
                        succes: function () {
                            $("#AddProductNotification").text("U heeft net een product toegevoegd. Herlaad de pagina om uw winkelwagentje te bekijken");
                        }
                    });


                };
                // $("#AddProductNotification").text("U heeft net een product toegevoegd. Herlaad de pagina om uw winkelwagentje te bekijken");
            },
            error: function (XMLHeeptRequest, textStatus, errorThrown) {
                alert(textStatus);
                alert(errorThrown);
            }
        });
        // alert("end");
        //  AddToCart(this);
        return false;
    });
   // return false;
});
// ProductId: $(orderlinkObject).parent().attr("data-productid"), Ammount: $(orderlinkObject).parent().parent().find("input#ammount").val()   

Вот как это происходит:

  • Получает вызванный (=ok): /Cart/ExistsInCart с параметром: идентификатор продукта и возвращает true в jSon
  • Но диалог не вызывается, и я не могу обновить его с помощью firebug.

1 ответ

Похоже, у вас проблемы с вашей областью применения.

У вас много $(this).attr("href") в анонимных функциях в успехе ajax. В этих функциях this != "a.orderlink",

Ты захочешь сделать var that = $(this) вверху вашего обработчика кликов, а затем использовать that.attr("href"),

Пример: http://jsbin.com/ivoniv/edit

Другие вопросы по тегам