0

jquery cloning is working, for example,

$("#treeFile" > ul:first > li:first ul > *).clone().appendTo("#dummyTree");

However when attempting to send this clone to a post ajax, the file is empty...

var cloneTree = $("#treeFile" > ul:first > li:first ul > *").clone();


$.post("tree.php", cloneTree);

When viewing firebug, this http request was successful but when viewing the file on the service file system, its empty...

5
  • What exactly are you trying to post, the html? Commented Mar 29, 2013 at 5:10
  • 1
    Are you sure your script is working? there is a syntax error in the posted code and why are you posting DOM Elements? What are you trying to achieve? Commented Mar 29, 2013 at 5:11
  • you cannot post a jquery object... you have to post an object {post1:"whatever",post2:"whatever2"...} Commented Mar 29, 2013 at 5:14
  • Yes, I'm trying to post the html content of the clone copy... Commented Mar 29, 2013 at 5:20
  • Can I post html source code? Commented Mar 29, 2013 at 5:23

3 Answers 3

1

There are couple of things

1) Remove the extra " around #treeFile and also > * from the end only if you want everything which is inside ul

 var cloneTree = $("#treeFile" > ul:first > li:first ul > *").clone(); //wrong
 var cloneTree = $("#treeFile > ul:first > li:first > ul").clone(); //correct    

2) You can try this in order to post data via ajax

var cloneTree = $("#treeFile > ul:first > li:first > ul").html();

JSFIDDLE : http://jsfiddle.net/5QBYW/1/

Sign up to request clarification or add additional context in comments.

1 Comment

i was preparing the fiddle .. i guess i am late in posting the answer :(
0

If its the HTML you need to POST, you can do:

$.post("tree.php", {html: cloneTree.html()});

Data cannot be posted to a server without parameter names. In the above code, the name of your parameter is html.

On the server side, you can access this HTML as $_POST['html']

Comments

0

You can pass html to the server as follows:

Note the syntax error in your code would result due to a misplaced quote:

var cloneTree = $("#treeFile > ul:first > li:first ul > *").clone();

$.post("tree.php", {html:cloneTree.html()});

Also, in case you were not aware, you do not need to clone the object to post its html. You could just send it directly:

$.post("tree.php", {html:$("#treeFile > ul:first > li:first ul > *").html()});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.