admin管理员组文章数量:1406937
After searching Google for hours, I'm still stuck with this problem. Hope you guys can help me out.
I am building an application that lets user design their pages for a photo album. It first loads the standard format for each page using an XML. The XML is loaded through an AJAX call using JQuery as in:
$.get('.php', function(responseXML) {
$xmlDoc= $(responseXML);
)}
The XML file is now loaded as an object, and I can perform JQuery methods on it, which reduces the amount of code for me.
Editing from the user side is saved in the $xmlDoc. So when a user drags a photo over the page, the new cordinates are saved as an attribute of that photo. After all the user editing has been done, I want to export the new XML and save it to the server. This is where my problem starts. Since I've loaded the XML as a JQuery object (by using $(responseXML)), I can not export it as an XML file anymore. I've checked this by calling $.isXMLDoc($xmlDoc), which responds with false.
Since it was so easy to convert the XML to an object, I guess there must be a way to do the other way around. Any ideas on this?
XML from original file:
<pages>
<page bgcolor="0099cc" titlecolor="f8f8f8" subtitlecolor="000000">
<title>test</title>
<subtitle></subtitle>
<photo id="458267411204" name="" picture=".jpg" height="540" width="720" x="25" y="0">
<creator id="712241204" name=""/>
</photo>
</page>
</pages>
After searching Google for hours, I'm still stuck with this problem. Hope you guys can help me out.
I am building an application that lets user design their pages for a photo album. It first loads the standard format for each page using an XML. The XML is loaded through an AJAX call using JQuery as in:
$.get('http://www.domain./ajaxcall.php', function(responseXML) {
$xmlDoc= $(responseXML);
)}
The XML file is now loaded as an object, and I can perform JQuery methods on it, which reduces the amount of code for me.
Editing from the user side is saved in the $xmlDoc. So when a user drags a photo over the page, the new cordinates are saved as an attribute of that photo. After all the user editing has been done, I want to export the new XML and save it to the server. This is where my problem starts. Since I've loaded the XML as a JQuery object (by using $(responseXML)), I can not export it as an XML file anymore. I've checked this by calling $.isXMLDoc($xmlDoc), which responds with false.
Since it was so easy to convert the XML to an object, I guess there must be a way to do the other way around. Any ideas on this?
XML from original file:
<pages>
<page bgcolor="0099cc" titlecolor="f8f8f8" subtitlecolor="000000">
<title>test</title>
<subtitle></subtitle>
<photo id="458267411204" name="" picture="http://www.domain./picture.jpg" height="540" width="720" x="25" y="0">
<creator id="712241204" name=""/>
</photo>
</page>
</pages>
Share
Improve this question
edited Apr 15, 2011 at 8:03
Bjorn
asked Apr 15, 2011 at 7:05
BjornBjorn
911 silver badge6 bronze badges
1
- possible duplicate of How to serialize a generic JavaScript object to XML – Alastair Pitts Commented Apr 15, 2011 at 7:07
3 Answers
Reset to default 5I found the solution. I make the Ajax-call as the following:
$.ajax({
url: "http://www.domain./ajaxcall.php"?,
type: "POST",
contentType: "application/xml",
processData: false,
data: $xmlDoc.context,
success: function(data) {
alert('success');
}
});
Then in ajaxcall.php I process the file and save it to the server:
$xmlcontent = $GLOBALS["HTTP_RAW_POST_DATA"];
$handle = fopen($_SERVER["DOCUMENT_ROOT"].'/userfiles/xml/book.xml', 'wb');
fwrite($handle,$xmlcontent);
fclose($handle);
I'm not quite sure whether it works with XML but with HTML is dose:
$('<div>').append($xmlDoc).html()
I wrote a small fiddle to demonstrate my solution: http://jsfiddle/scheffield/3RhhF/
Have a try.
ok It is not as straight forward to serialize the JavaScript object to XML. The GSerializer library can be of use to you
It can be found here
or you should be able to get the HTML from the element to which it was appended by just using .html()
$(".div").html()
This can be saved into the database
本文标签: javascriptSend JQuery DOM Object as XML to serverStack Overflow
版权声明:本文标题:javascript - Send JQuery DOM Object as XML to server - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744973912a2635403.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论