2012-01-15 41 views
0

問題在於在PHP和JQuery之間傳遞對象。在PHP和JQuery之間傳遞DOMDocument

在JQuery的表演$.post,我想檢索「get_domdoc.php」中產生的DOMDocument對象,然後能夠$.post回其他PHP文件,如:

$.post("get_domdoc.php", {url: url}, function(domdoc) 
    { 

    //prepare 'domdoc' to $.post it - in a usable format - to another PHP file 

    }); 

這可能嗎?感謝任何幫助。

+0

是否需要發佈?如果PHP文件要在同一個會話中運行,那麼檢索DOM HTML或XML並將其作爲字符串存儲在'$ _SESSION'中將重建爲下一個PHP頁面上的DOMDocument對象將更加實用(除非HTML或XML非常大) – 2012-01-15 17:15:52

回答

2

最直接的方法可能是turning it into a string in the sending PHP script,將其視爲jQuery中的字符串數據,並在接收PHP腳本中創建一個新的DOMDocument

理論上講,您可以使用DOMDocument對象,但感覺很糟糕(如果可能的話)。交換正確的XML看起來像是走向IMO的方式。

+0

我不知道我在想什麼,真的。首先使用$ str = $ domdoc-> saveHTML(),然後使用DOMDocument :: LoadHTML($ str)使其變得非常簡單。謝謝! – TMichel 2012-01-15 17:37:36