2012-05-07 70 views
1

這個jquery ui對話框填充了來自ajax調用(工程)的html和表單值。我想關閉或提交它,然後重新打開並重復使用它。我可以關閉並重新打開,但它仍舊有舊的值,然後添加新的值。它會在每次關閉並重新打開後繼續添加html值。關於這個問題有很多問題,但我沒有看到明確的答案。我已經嘗試過接近,空着,摧毀,但組合並不按我需要的方式工作。有任何想法嗎?重新打開jquery ui對話框,清空並刷新

$("#StoreForm").dialog({ 
    autoOpen:false, 
    width:500, 
    height:900, 
    modal:true, 
    buttons: { 
    OK: function() { 
    $('#StoreForm').dialog('close'); 
$(this).dialog('hide'); 
$(this).dialog('empty'); 
}, 
'Save': function() { 
    $(this).dialog('empty'); 
} 

} 

}); 


//additional code to click and open the dialog 

$(".sel").unbind('click'); 
$(".sel").on("click", function(e){ 
e.preventDefault();     
$("#StoreForm").dialog('open'); 
var valueSelected = $(this).closest('tr').children('td.item').text();         
$.ajax({ 
url: 'query/categories.cfc', 
dataType: 'json', 
cache: false, 
data: {method: 'getProductInfo', 
           queryFormat: 'column', 
          returnFormat: 'JSON', 
productID: valueSelected 

}, 
success: function(response, status, options){ 
$("#PROD_SUPER_ID").val(response.DATA.PROD_SUPER_ID[0]); 

$("#color").val(response.DATA.COLOR_ATTRIB); 

          $("#SIZE_ATTRIB").val(response.DATA.SIZE_ATTRIB); 

$("#price").val(response.DATA.PRICE); 
var w = []; 
w.push("<p>", response.DATA.ICON[0], "</p>", "<p>", 
     response.DATA.FULL_DESCRIPTION [0], "</p>") 
          $("#StoreForm").prepend(w.join("")); 

回答

0

我發現你可以關閉對話框並清空html,它將清除這種類型的對話框設置。對於重新開放,我在第一個成功響應中嵌套了第二個ajax調用。

//set up dialog with options 

$("#StoreForm").dialog({ 
autoOpen: false, 
width: 500, 
height: 500, 
modal: true, 
buttons: { 
    Cancel: function(){ 

     $('#StoreForm').dialog('close'); 
     $('#StoreForm').html(""); 

    }, 

//pop-up individual items 

    "Add to Cart": function(){ 
      $.ajax({ 
      url: $("#storeCart").attr('action'), 
      data: $("#storeCart").serializeArray(), 
      type: 'POST', 
      success: function(response){ 

        var name = $("#name"), 
    email = $("#email"), 
    password = $("#password"), 
    allFields = $([]).add(name).add(email).add(password), 
    tips = $(".validateTips"); 

if you have any questions please respond. Thanks