I send request to servlet with a link and want to receive response with html code of this link. Servlet receives the link, handles it and sends html code in response, but I can't receive it with ajax.
Request & Response in servlet - it works fine!
request.getParameter("url");
response.getWriter().print(responseText);
jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title></title>
</head>
<body >
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<div height="100%">
<div height="30%">
<div>Some text here</div>
<div> <form id="submitForm">
<input type="text" width="600px" id="url">
<button id="ajaxSubmit" type="submit" >Submit</button>
</form></div>
<br/>
<div id="div2"></div>
</div>
<div height="60%">
<iframe id="FileFrame" name="iframe" src="" name="myFrame" height="100%" width="100%" frameborder="0" >
</iframe>
</div>
<script type="text/javascript">
$("#submitForm").submit(function(){
console.log("onclick");
var url = $("#url").val();
$.post('proxyServer', {url: url}, function(responseText) {
console.log("text received");
var iframe = document.getElementById('FileFrame');
var iframedoc = iframe.document;
if (iframe.contentDocument)
iframedoc = iframe.contentDocument;
else if (iframe.contentWindow)
iframedoc = iframe.contentWindow.document;
if (iframedoc) {
//iframedoc.open();
iframedoc.write(responseText);
iframedoc.close();
} else {
alert('Cannot inject dynamic contents into iframe.');
}
}).error(function(p1, p2, p3){
alert("error!");
console.log(p1 + p2 + p3);
});
});
</script>
</div>
</body>
</html>