I have a JSP page that displays an HTML block. Under normal use, I load the contents of the JSP using AJAX (specifically using jQuery.load()) and embed it on the page. Now I need to be able to upload this HTML block to a different domain, which means that restrictions with the same source will not allow me to use “regular” AJAX.
This block is included in several places, some of which will be in one domain, and some of them will be in alternative domains. I would prefer it to continue to work the way it currently works, unless a specific parameter is passed (in all likelihood, it will be a callback function that is passed to support JSONP).
My conceptual solution (so far) is JSONP output with one KEY / VALUE pair, having full HTML output as VALUE.
PROBLEM: I cannot find a way to get buffered output waiting to be sent when the JSP finishes rendering and changing it (in this case, to replace the actual newlines with "\ n"., I get an error Unterminated String Literalwhen my JSONP function hits the first new line .
Example:
<%@page contentType="text/html"%>
<%
String callback = request.getParameter("callback");
%>
<% if(callback != null) { %>
// JSONP Function call, defining Key/Value Pair
// New lines break because JavaScript strings cannot cross lines
<%= callback %>({"key":'
<% } %>
<div id="my_content">
...
</div>
<% if(callback != null) { %>
'}) // End of JSONP Function Call
<% } %>