在Xpages

时间:2016-08-31 20:22:53

标签: xpages lotus-notes xpages-ssjs xpages-extlib

我试图使用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()

有谁知道我做错了什么?

由于

1 个答案:

答案 0 :(得分:1)

您必须在脚本中返回值,并且您的客户必须等待回调功能的回答。

这是一个有效的例子:

<?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')类似的其他代码。脚本只需要返回一些内容......