Reputation: 83
I'm trying to use jsonRpcService to print a value on console. Just for testing. But when i call the method i recieve this error on browser console:
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(…)
Here is the image of the error: https://i.sstatic.net/T5ekl.jpg
I already searched a lot for one solution to this error but i got nothing.
This is the code that i'm using:
<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>
And this is the code that i'm using on console to call the function
metodos.teste()
Does anyone knows what i'm doing wrong?
Thanks
Upvotes: 3
Views: 333
Reputation: 30960
You have to return a value in your script and your client has to wait for answer with a callback function.
This is a working example:
<?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>
When you click on button "Test" an alert box shows up with the message "teste".
You can add additional code before return 'teste'
like your original print('teste')
. The script just has to return something...
Upvotes: 1