2012-01-15 82 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