作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 jsonRpcService 在控制台上打印一个值。只是为了测试。但是当我调用该方法时,我在浏览器控制台上收到此错误:
POST http://localhost/Teste.nsf/Teste.xsp/RpcService?$$viewid=!ei0pdt23xx! 400 (Bad Request)
Error: Unable to load /Teste.nsf/Teste.xsp/RpcService?$$viewid=!ei0pdt23xx! status:400(…)
Unable to load /Teste.nsf/Teste.xsp/RpcService?$$viewid=!ei0pdt23xx! status:400
Error: Unable to load /Teste.nsf/Teste.xsp/RpcService?$$viewid=!ei0pdt23xx! status:400(…)
Error: Unable to load /Teste.nsf/Teste.xsp/RpcService?$$viewid=!ei0pdt23xx! status:400(…)
这是错误的图像: http://i.stack.imgur.com/T5ekl.jpg
我已经搜索了很多解决此错误的方法,但一无所获。
这是我正在使用的代码:
<xe:jsonRpcService id="jsonRpcService1" serviceName="metodos"
pathInfo="RpcService">
<xe:this.methods>
<xe:remoteMethod name="teste" script="print('teste')"></xe:remoteMethod>
</xe:this.methods>
</xe:jsonRpcService>
这是我在控制台上用来调用函数的代码
metodos.teste()
有人知道我做错了什么吗?
谢谢
最佳答案
您必须在脚本中返回一个值,并且您的客户端必须使用回调 函数等待响应。
这是一个工作示例:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view
xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xe="http://www.ibm.com/xsp/coreex">
<xe:jsonRpcService
id="jsonRpcService1"
serviceName="metodos"
pathInfo="RpcService">
<xe:this.methods>
<xe:remoteMethod
name="teste"
script="return 'teste'">
</xe:remoteMethod>
</xe:this.methods>
</xe:jsonRpcService>
<xp:button
value="Test"
id="button1">
<xp:eventHandler
event="onclick"
submit="false">
<xp:this.script><![CDATA[
var deferred = metodos.teste();
deferred.addCallback(function(result) {
alert(result);
});]]></xp:this.script>
</xp:eventHandler>
</xp:button>
</xp:view>
当您单击“测试”按钮时,会出现一个带有消息“teste”的警告框。
您可以在 return 'teste'
之前添加额外的代码,就像您原来的 print('teste')
一样。该脚本只需要返回一些东西...
关于xpages - 在 Xpages 上使用 jsonRpcService 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39258387/
我正在尝试使用扩展库组件远程服务 (xe:jsonRpcService)。我从 here 得到了一些提示和 here .基本上我正在尝试使用 RPC 保存文档。问题是文档已保存,但它不保存 XPage
我正在尝试使用 jsonRpcService 在控制台上打印一个值。只是为了测试。但是当我调用该方法时,我在浏览器控制台上收到此错误: POST http://localhost/Teste.nsf/
我是一名优秀的程序员,十分优秀!