How to convert jquery collection to xml string for an ajax request

Posted by Jim on Stack Overflow See other posts from Stack Overflow or by Jim
Published on 2011-01-12T02:49:50Z Indexed on 2011/01/12 2:53 UTC
Read the original article Hit count: 198

Filed under:

I created a jquery collection that stores xml as follows:

var rh_request = $('') .attr('user_id', user_id) .attr('company_id', company_id) .attr('action', 'x');

I want to post it to my server via an ajax request as follows:

$.ajax({ type: "POST", url: mywebsiteURL, processData: false, dataType: "xml", data: rh_request.html(), success: mycallbackfunction });

My problem is that the "data" parameter of the ajax call needs a string version of the xml and it seems neither Jquery's .html() or .text() function yields this. I have older code that used straight javascript to form the outgoing xml and calling the DOM .xml() function yielded a string that worked. How is this done with a jquery collection???

© Stack Overflow or respective owner

Related posts about jQuery