I am using jQuery to make a POST to a PHP file with the HTML content of a div. The HTML content contain tables, inputs, smaller divs and I would like to grab the content of the main DIV and send it to the database. The only option I could think of is the POST method but I don't know if I can send plain HTML with it. Are there any other options for sending HTML content from a div to a PHP file to be inserted into MySQL ?
Thanks.
EDIT: I am now able to send full HTML data with jQuery's POST. However, my HTML characters from that DIV gets transformed into special characters. Example: ">" would become ">" and when that happens, my POST data is limited to where the first special character appears because I do my ajax POST like this:
var data = 'id='+ currid +'&html='+ div_html;
$.ajax({
type: "POST",
url: "file.php",
data: data,
.......................
.......................
Using this code is not ok because div_html contains other "&" characters so it would be considered as another POST parameter to be sent.
Any workarounds ?
Thanks again.
I used the technique what u have replied above, it works fine but my problem is i need to generate a pdf conent using john as text . I have been able to echo the passed data. but getting empty in when generating pdf uisng below content ples check
If you want to send an arbitrary amount of data to your server, POST is the only reliable method to do that. GET would also be possible but clients and servers allow just a limited URL length (something like 2048 characters).
I don't see why you shouldn't be able to send html content via a post.
if you encounter any issues, you could perhaps use some kind of encoding / decoding - but I don't see that you will.
As far as you're concerned once you've "pulled out" the contents with something like .html() it's just a string. You can test that with
The alert text is string. As long as you don't pass it to a parser there's no magic about it, it's a string like any other string.
There's nothing that hinders you from using .post() to send this string back to the server.
edit: Don't pass a string as the parameter data to .post() but an object, like
jquery will handle the encoding of the parameters.
If you (for whatever reason) want to keep your string you have to encode the values with something like escape().