2010-06-05 35 views
0

我想從我的表單發佈數據到加載外部內容的jquery對話框。通過ajax傳遞數據到對話框Jquery

我該序列化工程(出現在URL)形式的數據,但該對話框不會打開:

 $("#wavajax button").click(function() { 
    $.post({url: 'player/index.php', data: $("#wavajax").serialize(), 
     success: function (data) { 

        $("#recordingdialog").load("player/index.php", [], function(){ 
       $("#recordingdialog").dialog("open"); 

       } 
    }); 
    return false; 
}); 

什麼我做錯了,我要對正確的方式???

+0

在此之前您是否正在創建對話框?還不確定你爲什麼要做一個POST,然後GET一個相同的URL? – 2010-06-05 10:07:51

+0

我試圖將數據發佈到player/index.php,並且該頁面在 – user342391 2010-06-05 10:10:44

+0

中的發佈數據的對話框中打開,無論「#recordingdialog」是放置在您的標記中的div幷包括所有對話框UI依賴關係。 – jAndy 2010-06-05 10:11:23

回答

4

認爲這是你追求的:

$("#wavajax button").click(function() { 
    $.post('player/index.php', $("#wavajax").serialize(), function (data) { 
     $("#recordingdialog").html(data).dialog("open"); 
    }); 
    return false; 
}); 

你已經從POST獲取HTML內容發回(或至少我認爲是這樣),所以只使用.html()將該響應放在#recordingdialog中,然後進行對話調用。如果你以前沒有創建帶有選項的對話框,然後就.dialog()就足夠了,.dialog('open')適用於當你與各種選項對話框創建較早,現在想要打開它,像這樣:

$("#recordingdialog").dialog({ 
    //other options, width, height, etc... 
    autoOpen: false 
}); 

You can find a full list of these options here

+0

這很好。但是,當我關閉對話框並單擊再次打開時,沒有任何反應會出現任何想法,爲什麼o巧妙的暱稱 – user342391 2010-06-05 11:01:39

+0

@user不應該是這種情況......是否還有其他與'#recordingdialog'元素混淆的其他內容? – 2010-06-05 11:08:57

+0

是的,我有一個標題包含在播放器/ index.php文件的頂部。刪除它,一切都很好。你是男人! – user342391 2010-06-05 11:13:37

0

它可能是一個更好的主意,首先顯示對話框並加載內容。

$('#recordingdialog').dialog('destroy'); // just in case 
$('#recordingdialog').dialog({ 
    position: 'center', 
    // some more options 
    open: function(e, ui){ 
     $.post('player/index.php', data: $("#wavajax").serialize(),function (data){ 
       $("#recordingdialog").html(data); 
     }); 
    } 
}); 

在您的點擊處理程序中。

UI Dialog Doc

+0

這種方法留下了一個空白的對話框,等待內容加載,然後當它閃爍時,我不相信這是一種應該使用的方法....也檢查你的$ .post()調用,它不是有效的:) – 2010-06-05 10:21:21

+0

我想這種方法比按下按鈕後不發生任何事情更好。在打開的對話框中插入某種'loading' gif可能是個好主意。 – jAndy 2010-06-05 10:23:40

+0

你當前的答案會拋出一個javascript語法錯誤,所以它不會更好;) – 2010-06-05 10:25:56

0

好吧我有這個工作:

 $("#recordingdialog").dialog({ 
    //other options, width, height, etc... 
    modal: true, 
     bgiframe: true, 
     autoOpen: false, 
     height: 550, 
     width: 550, 
     draggable: true, 
     resizeable: true, 
     title: "Play Recording",}); 


$("#wavajax button").click(function() { 
    $.post('player/index.php', $("#wavajax").serialize(), function (data) { 
     $("#recordingdialog").html(data).dialog("open"); 
    }); 
    return false; 
}); 

感謝尼克!但有一個問題。當我關閉對話框並單擊按鈕時再次打開它沒有任何反應,爲什麼不呢?