2012-01-31 49 views
0

我使用$ .post()從數據庫中檢索內容,然後我想用它來操作表單值。一旦完成,我想打開jQuery對話框。這是我寫的一個非常簡單的「編輯事件」系統。我只是無法讓對話框在$ .post()內打開,如果我在$ .post()之外執行它,表單值將返回空。jQuery發佈和對話框

我理解它不起作用的概念,因爲如果回調成功,腳本將繼續運行,但是有沒有其他方法可以執行此操作?

我的代碼:

// Edit a banner: 
$("input[name='eventEditBtn']").click(function() { 
    var eventID = $(this).attr("rel"); 
    $.post("www/scripts/ajax/getEventInfo.php",{id : eventID},function(data) { 
     if(data.success == true) { 
      var info = data.info; 
      $("input[name='editEventName']").val(info.name); 
      $("input[name='editEventDate']").val(info.date); 
      $("input[name='editEventTime']").val(info.time); 
      $("textarea[name='editEventSummary']").val(info.summary); 
      $("textarea[name='editEventDescription']").val(info.description); 
      $("#editEventCurrentCategory").html("The current category is: "+info.categoryName); 
      $("input[name='editEventVenue']").val(info.venue); 
      $("input[name='editEventCost']").val(info.cost); 
      $("#editEventCurrentStatus").html("The current status is: "+info.categoryName); 
      $("#editEventContainer").dialog({width: 600, title: "EDIT EVENT:"}); 
     } else { 
      $("<div />").dialog("An error has occured retrieving this event information."); 
      return false; 
     } 
    }); 
    return false; 
}); 
+0

您是否在控制檯中遇到錯誤?幾個選項。在打開對話框之前設置一個短暫的超時時間,或者先實例化對話框並隱藏/關閉它,然後在當前實例化它的位置打開它。 – j08691 2012-01-31 20:21:26

回答

1

也許是因爲輸入被對話框之前修改正在初始化?嘗試$。員額這樣調用之前初始化它,例如:

$('#editEventContainer').dialog({ 
      autoOpen: false, 
      width: 600, 
      title: "EDIT EVENT:" 
}); 

,然後你的$。員額調用打開使用對話框:

$('#editEventContainer').dialog('open'); 

還要記住檢查的選擇是對。