Thanks Anthony. I checked it and it was throwing error as my web service definition was wrong. Also, my jQuery code was incorrect. I fixed both and it started working. Here I am posting my code if it could help anybody in future for reference.
jquery: function nextprevajaxcall(nextprevindicator) { var req = {jsonrpc:"2.0", method: "nextprevexample",id:(new Date).getTime()}; req.params=[nextprevindicator]; $.ajax({ url: "http://127.0.0.1:8000/adv01/default/call/jsonrpc", data: JSON.stringify(req), dataType: "json", type: "POST", contentType: "application/json", success: function(rpcRes) { //alert(JSON.stringify(rpcRes)); $("#lblexample").text(rpcRes.result[1]); $("#txtexamplereviewed").val(rpcRes.result[1]); }, error: function(err, status, thrown) { alert(thrown);//alert(status);alert(thrown); } }); } $(document).ready(function(){ $("#btnNext").click(function(){ nextprevajaxcall(1); return false; }); $("#btnPrevious").click(function(){ nextprevajaxcall(0); return false; }); }); web2py controller: @service.json @service.jsonrpc def nextprevexample(nextprevindicator): #print nextprevindicator exampleid,exampletext=getcorrespondingexample(nextprevindicator) return exampleid,exampletext On Thursday, 4 September 2014 10:49:27 UTC+5:30, Anthony wrote: > > Have you confirmed that the function is actually getting called? Anything > in request.body? > > Anthony > > On Thursday, September 4, 2014 12:42:06 AM UTC-4, Gliese 581 g wrote: >> >> I am trying to make ajax jsonrpc call to my web service using jQuery as >> given below: >> >> $(document).ready(function() { >> $("#btnNext,#btnPrevious").click(function() { >> var req = { >> jsonrpc: "2.0", >> method: "nextprevexample", >> id: (new Date).getTime() >> }; >> req.res = { >> name: 'aajas' >> }; >> $.ajax({ >> url: "http://127.0.0.1:8000/adv01/default/call/jsonrpc", >> data: JSON.stringify(req), >> dataType: "json", >> type: "POST", >> contentType: "application/json", >> success: function(rpcRes) { >> alert(rpcRes.result); >> $("#lblexample").text(rpcRes.result[1]); >> $("#txtexamplereviewed").val(rpcRes.result[1]); >> }, >> error: function(err, status, thrown) { >> alert(thrown); //alert(status);alert(thrown); >> } >> }); >> return false; >> });}); >> >> I am trying to access it in my web2py web service. The code of web >> service is as follows: >> >> @service.json @service.jsonrpc def nextprevexample(): >> print request.post_vars >> exampleid,exampletext=getcorrespondingexample() >> return exampleid,exampletext >> >> But the problem is I don't get anything in post_vars. >> >> I tried to search entire request object to find any property which would >> give me posted data but didn't find one. >> >> Please let me know if I have doing anything wrong over here. >> > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.