I faced the same scenario in incorporating jquery mobile in ASP.Net web form because of the complex html result i return. I was able to provide a fix by returning an encoded html from the server side. The encoded html is further encoded in utf8 format. This result will be finally decoded for output in a div or any control of choice.
This is the pseuso-code :
ASP.NET (vb style, use any language of your choice) output must be returned with
dim Result as string=Server.HTMLEncode(htmlouput)
return Result
From the javascript section with jquery
$('#<%=btn.ClientID %>').click(function() {///begin
$.ajax({
type: "POST",
url: "page.aspx/staticmethod",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "html",
success: function(html) {
try {
var out = encode_utf8(html);
$('#result').html(htmlDecode(encode_utf8(html)));
} catch (ex) {
alert(ex);
}
},
error: function(msg) {
//alert error
}
})
return false;
}); //ends
//decode html
function htmlDecode(value) {
if (value) {
return $('<div />').html(value).text();
} else {
return '';
}
}
//remove the 'd' encapsulator and other unwanted characters
function removedencapsulator(value) {
return value.replace('{"d":"', '').replace('"}', '').replace(/(?:\s+)? <(?:\s+)?/g, '<').replace(/(?:\s+)?>(?:\s+)?/g, '>').replace(/\s+/g, ' ');
}
////replace the quote string in the return query
function replacequote(value) {
return value.replace('\u0027', '');
}
//unescape the utf-8 code
function encode_utf8(s) {
var normalizedData = replacequote( removedencapsulator(s));
return unescape(encodeURIComponent(normalizedData.toString()));
}
I hope this solves the question.