0

I need to call a invoke a remote rpc procedure via jquery. I user jquery-json plugin for this purpose. >>https://github.com/datagraph/jquery-jsonrpc/

<input style='width:100px;float:left;margin:20px 10px 0px 10px;' type="button" id="JsonHangup"  class="btn btn-primary" value="HangUp"   />




    <script src="js/jquery.min.js"></script>
<script src="js/jquery.json-1.3.min.js"></script>
<script> src="js/jquery-jsonrpc-master/jquery.jsonrpc.js"</script>

<script>
$(document).ready(function(){
  $("#JsonHangup").click(function(){
   alert("The paragraph was clicked.");

$.jsonRPC.setup({
  endPoint: 'https://172.31.0.164:42338/jsonrpc/API/hangup'
});
$.jsonRPC.request('test', {
  params: ["hoi"],
  success: function(result) {
    /* Do something with the result here */
  },
  error: function(result) {
    /* Result is an RPC 2.0 compatible response object */
  }
});


});
});
</script>

It gives following error:

Uncaught TypeError: Cannot call method 'setup' of undefined 

Can anyone help me on this? Thanks in advance.

Kasinath Kottukkal
  • 2,471
  • 4
  • 22
  • 28

1 Answers1

1

You need:

<script src="js/jquery-jsonrpc-master/jquery.jsonrpc.js"></script>

instead of:

<script> src="js/jquery-jsonrpc-master/jquery.jsonrpc.js"</script>

You're closing the script tag at the wrong place which make the browser cannot load the file properly. It should be closed after your src attribute, not before.

Felix
  • 37,892
  • 8
  • 43
  • 55
  • Thanks. Now it show a diffrent error: "Uncaught ReferenceError: $ is not defined ". Please refer: http://pastebin.com/kwnBEwTU – Kasinath Kottukkal Feb 28 '14 at 15:39
  • Please check `js/jquery.min.js` is the correct file path or not. Seem like you cannot load `jQuery` properly here – Felix Feb 28 '14 at 15:41
  • They are indeed at the right location. Is there any particular version of Jquery I sould use. I even put jquery-1.11.0.min.js instead. But still no luck. – Kasinath Kottukkal Feb 28 '14 at 15:49
  • Try to use direct link instead `` – Felix Feb 28 '14 at 16:50
  • I used direct link. It eliminates "$ is not defined" error but old error reappears: " Uncaught TypeError: Cannot call method 'setup' of undefined agent.htm:124 (anonymous function) agent.htm:124 jQuery.event.dispatch jquery.js:3242 elemData.handle.eventHandle" – Kasinath Kottukkal Feb 28 '14 at 17:03
  • Did you close the ` – Felix Feb 28 '14 at 17:05
  • When I close script tag for direct link like it gives me error `Uncaught ReferenceError: $ is not defined `. When I use the exact line you given in last line that error is gone. But when I click on Button following error is shown: `Uncaught TypeError: Cannot call method 'setup' of undefined agent.htm:124 (anonymous function) agent.htm:124 jQuery.event.dispatch jquery.js:3242 elemData.handle.eventHandle` – Kasinath Kottukkal Feb 28 '14 at 17:11
  • No, you need to use `` – Felix Feb 28 '14 at 17:14
  • Thanks. I am doing it that way. This is how it looks now. ` `. I am following [link]http://stackoverflow.com/questions/21204713/understanding-json-rpc-in-perl in which a JSON rpc client example is given. It seems that error occurs at line `$.jsonRPC.setup`. : `Uncaught TypeError: Cannot call method 'setup' of undefined agent.htm:124 ...` – Kasinath Kottukkal Feb 28 '14 at 17:24
  • Looping @David-SkyMesh – Kasinath Kottukkal Feb 28 '14 at 17:42