1

このコードが機能しないのはなぜですか?

その間(機能させようとしている)、かなりの時間を変更しましたが、解決策が見つかりません。

誰にもアイデアがありますか?コンソールにエラーはありません。

まず、ダイアログを開く必要があるかどうかをチェックします。

ワークフローは次のとおりです。

If DialogRequired => Dialog.Click = OK --> ajax 呼び出しを実行する If DialogRequired => Dialog.Click = Cancel --> 何もしない If Dialog NOT Required => 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 にパラメーター: 製品 ID を指定し、jSon で true を返す
  • しかし、ダイアログが呼び出されず、firebug で更新できないようです。
4

1 に答える 1

0

スコープに問題があるようです。

$(this).attr("href")ajaxの成功には無名関数がたくさんあります。それらの機能this != "a.orderlink"で。

var that = $(this)クリック ハンドラーの上部で実行してから、 を使用する必要がありますthat.attr("href")

例: http://jsbin.com/ivoniv/edit#javascript

于 2012-01-19T16:29:59.163 に答える