gpt4 book ai didi

xpages - 在 Xpages 上使用 jsonRpcService 时出错

转载 作者:行者123 更新时间:2023-12-02 03:12:16 25 4
gpt4 key购买 nike

我正在尝试使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com