我已经在Worklight服务器上部署了适配器,并且有一些要求我从外部调用worklight适配器作为休息服务器,它工作正常并根据需要返回数据但不是给json输出它是给HTML
<!DOCTYPE html><html><head><meta charset="UTF-8" /><title>Invoke Procedure Result</title><script src="/secure/console/js/jquery-1.6.min.js"></script><style> textarea { width: 100%; } .textwrapper { margin: 5px 0; padding: 3px; }</style></head><body onload="attachEvent();"><div><span id="invRes">Invocation Result of procedure: 'Authentication' from the Worklight Server</span>: </div><div id="target"><textarea rows="20">{
"RESPONSE": {
"USER_ID": "292265"
},
"errors": [
],
"info": [
],
"isSuccessful": true,
"responseHeaders": {
"Content-Length": "1195",
"Content-Type": "text\/xml;charset=ISO-8859-1",
"Date": "Thu, 21 Nov 2013 10:10:13 GMT",
"Server": "Oracle GlassFish Server 3.1.2.2",
"X-Powered-By": "Servlet\/3.0 JSP\/2.2 (Oracle GlassFish Server 3.1.2.2 Java\/Oracle Corporation\/1.7)"
},
"responseTime": 4234,
"statusCode": 200,
"statusReason": "OK",
"totalTime": 4235,
"warnings": [
]
}</textarea></div><script>function attachEvent() {$('#target').ajaxError(function(e, xhr, ajaxOptions, thrownError){$(this).text("Error: Please ensure that the XML input and XSL transformation are valid and try again.");});}function run_xslt() {var xml = $('#originalXML').val();var xsl = $('#originalXSL').val();$.post('/secure/dev/xslt',{'xml':xml,'xsl':xsl},function(data, textStatus, XMLHttpRequest){$('#target').empty();json = $("<textarea></textarea>");json.attr("rows",25);json.text(data);$('#target').append(json);$('#invRes').text('Result of Local XSL Transformation');},'text');}</script></body></html>
代码中的我再次从HTML解析它并将json存储到字符串中。然后我才能使用它。这是下面给出的url,用于根据worklight文档在外部调用适配器。
答案 0 :(得分:4)
从URL中删除/ dev / component,它仅用于开发简易目的。如果没有它,你将获得你的JSON。
答案 1 :(得分:1)
我有同样的问题,在阅读了Anton的答案之后,我将Ajax调用的“dataType”设置为“text”,然后编辑响应以删除/ * - secure-和* /然后解析字符串以获取JSON“JSON.parse(theString)”
$.ajax({
type: 'POST',
url: ajaxURL,
async: true,
cache: true,
timeout: 5,
dataType: "text",
success: function(data){
data = data.replace("/*-secure-","");
data = data.replace("*/","");
var dataJSON = JSON.parse(data);
//Do success
},
error: function(data, statusCode){
//Do error
}
});