I would (in fact, do :-) ) have a form with a hidden field, copy the content of the div to the field, and then submit the form to a hidden (display: none
) iframe.
Including a hidden iframe on the page:
<iframe name="formTarget" src="blank.html" style="display: none">
(E.g., it's initially blank. I actually literally use a blank.html
file which is exactly what it sounds like, instead of (say) about:blank
because the latter doesn't works quite correctly in some cases; I don't recall the details.)
Telling the form to submit to the iframe and trigger your ashx file:
<form ... action="your.ashx" target="formTarget" ... >
Copying the content of the div to the field:
$("#fieldId").val($("#divId").html()); // Either .html() or .text(), depending on what you want
Submitting the form:
$("#formId").submit();
(Fill in the various "..."s appropriately.)
In my case, I show an overlay div telling the user what I'm doing and start a timer that watches for the content of the iframe (for error messages) and for a status cookie (see this answer for more about the cookie trick). The overlay gets updated or removed depending on the result.