开发者

Make JSON-RPC jQuery plugin work with GAE ProtoRPC

开发者 https://www.devze.com 2023-03-01 17:41 出处:网络
I am trying to make these two libraries work together. But I am not sure they can connect out of the box开发者_JS百科. Before using JSON-RPC plugin I did it successfully with standard $.ajax functiona

I am trying to make these two libraries work together. But I am not sure they can connect out of the box开发者_JS百科. Before using JSON-RPC plugin I did it successfully with standard $.ajax functionality. Could you please give me some short example of how a client-side function should look and the entry point for this on GAE side.

Or maybe there should be a special ProtoRPC jQuery library created to make this work easily?

JSON-RPC plugin homepage


ProtoRPC doesn't use the JSON-RPC message format. It uses a simpler format where each API method provides its own endpoint, rather than one endpoint that takes a method name as part of the request dictionary.

Here's the example they provide for $.ajax:

$.ajax({url: '/hello.hello',
          type: 'POST',
          contentType: 'application/json',
          data: '{ my_name: Bob }',
          dataType: 'json',
          success: function(response) {
            // The response is { hello: "Hello there, Bob!" }
            alert(response.hello);
          }
         });

Do you really need a special jQuery library for this? I'm not sure it can get much simpler.


We definitely need to develop a general purpose protorpc library for users. After that, it would be best to write a jquery plugin that works with it.

I actually thought about getting a way for ProtoRPC to support JSON-RPC as a separate protocol, however there may be some things about JSON-RPC that make it incompatible with ProtoRPC. Two things:

  • JSON requests allow for a list of arbitrary types in its parameters. ProtoRPC takes a single well defined type.

  • JSON fields and lists may contain arbitrary types. ProtoRPC fields and lists can only contain a single type.

I wish I had a better answer for you.


I'm working on the same idea, and have posted a similar question here.

I found that ProtoRPC does give a JSON response if your request has ContentType application/json, and jqGrid will produce this if you include ajaxGridOptions: { contentType: 'application/json; charset=utf-8' }, in your grid options, but that still leaves the problem that ProtoRPC only accepts one well-defined parameter, while jqGrid by default tries to upload 5 or so url-formatted parameters, even when you set it to POST instead of GET.

I'm currently trying to use the grid.postext.js plugin to get round this, so far without success.

0

精彩评论

暂无评论...
验证码 换一张
取 消