While sending a JSONObject response to my dojo 1.9.3 request/xhr callback function I receive a Invalid character synatx error. I checked my JSON format with JSONLint and its valid. Really confused by what I'm doing wrong.
JSON format being sent:
{
"issuer":"CN=***** CA , OU=*******, O=*********, L=****, ST=***, C=**",
"Thumbprint":"*********",
"valid to":"Mon *************",
"valid from":"*****",
"version":2
}
Servlet Code:
JSONObject cert = new JSONObject();
cert.put("version", x509certificate.getVersion());
cert.put("valid from", x509certificate.getNotBefore());
cert.put("valid to", x509certificate.getNotAfter());
cert.put("issuer", x509certificate.getIssuerDN().getName());
cert.put("Thumbprint", getThumbPrint(x509certificate));
System.out.println(cert);
System.out.println(cert.toString());
out.print(cert);
DOJO/HTML Code:
<body class="claro">
<script>dojoConfig = {parseOnLoad: true}</script>
<script src='dojo-release-1.9.3/dojo/dojo.js' ></script>
<script type="text/javascript">
require(["dojo/dom", "dojo/on", "dojo/request/iframe", "dom/dom-form", "dojo/dom-
construct", "dojo/json",
"dojo/domReady!"],
function(dom, on, iframe, domForm, domConst, JSON){
on(dom.byId("startButton"), "click", function(){
domConst.place("<p>Requesting...</p>", "output");
iframe("addUser",{
method:"POST",
form:"theForm",
handleAs: "json",
}).then(function(cert){
alert("data received!");
domConst.place("<p>data: <code>" + JSON.stringify(cert) + "</code></p>", "output");
}, function(err){
alert("data denied!!!");
alert(err);
}); }); });
</script>
<form id="theForm" method="post" enctype="multipart/form-data">
<input type="text" name="fname" value="Hello" /><br />
<input type="text" name="lname" value="World" /><br />
<input type="file" name="fileName" value="World" /><br />
<button type="button" id="startButton">Start</button>
</form>
<h1>Output:</h1>
<div id="output"></div>
<button type="button" id="startButton">Start</button>
</body>
</html>