2012-01-19 6 views
1

このコードが機能しないのはなぜですか?このAjaxの条件付きダイアログが機能しないのはなぜですか?

一方、私はそれを改善しましたが、解決策を見つけることができませんでした。

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

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

これはワークフローです:

DialogRequired => Dialog.Click = OKならば - DialogRequired => Dialog.Click =キャンセルした場合> AJAX呼び出し を実行 - >何も しないダイアログが不要な場合は= >これは、それがどのようになるで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() 

を実行します。

  • パラメータ:製品IDを持つCart/ExistsInCartが呼び出され、jSonでtrueを返します。
  • ダイアログが呼び出されず、Firebugで更新できないようです。
+0

それはすべてのエラーをスローしていますか? – Abadon

+2

何が問題なのですか?何が効いていますか? –

+1

"not working"を定義してください。実際に何をしているのか、あなたのコンソールに何らかのエラーがあります。 –

答えて

0

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

あなたはajaxの成功の匿名機能で$(this).attr("href")の多くを持っています。それらの機能ではthis != "a.orderlink"

クリックハンドラの上部でvar that = $(this)を上にして、that.attr("href")を使用します。

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

+0

私の質問が更新されました。コインシデンスによって、私は最初にhrefをvarに変更しました。しかし、これは私を助けませんでした。 – NicoJuicy

関連する問題