如何让jqGrid与Appengine的ProtoRPC一起使用 [英] How to get jqGrid working with Appengine's ProtoRPC

查看:83
本文介绍了如何让jqGrid与Appengine的ProtoRPC一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助我解决一个简单的问题吗?我正在尝试让Google App Engine提供可与jqGrid(v4.0.0)一起使用的JSON数据,但似乎还有最后一个障碍.我的应用程序是一个简单的待办事项列表示例,使用ProtoRPC的表单查询界面,我得到的输出如下:

Can anyone please help with what I presume is a simple problem? I'm trying to get Google App Engine to serve JSON data that I can use with jqGrid (v4.0.0), but I seem to have a final fence to jump over. My application is a simple To-Do list example, and using ProtoRPC's form query interface I get output like:

{
rows: [
  {
    status: Planning,
    folder: HPM,
    context: WORK,
    title: PURSUE HPM ACTIONS,
    },
  {
    status: Planning,
    folder: PLANNED MAINTENANCE,
    context: WORK,
    title: PM ASBESTOS,
    },

我尝试使用以下jqGrid设置来解决这个问题:

I try to pick this up with the following jqGrid settings:

      jQuery("#tasklist").jqGrid({
        url:'http://localhost:8084/postservice.get_tasks',
        datatype: 'json',
        mtype: 'GET',
        colNames:['Task','Folder', 'Context','Status'],
        colModel :[ 
          {name:'title', index:'Task', width:120}, 
          {name:'folder', index:'Folder', width:40}, 
          {name:'context', index:'Context', width:32}, 
          {name:'status', index:'Status', width:32} ], 
        pager: jQuery('#pager'),
        rowNum:10,
        jsonReader: {repeatitems:false, cell:'' },
        rowList:[10,20,30],
        sortname: 'folder',
        sortorder: "desc",
        viewrecords: true,
        imgpath: 'themes/basic/images',
        caption: 'My Jobs'
      }); 

但是,当我运行此代码时,会得到以下两个响应之一:如果我将mtype保留为GET,则jqGrid会尝试传递被ProtoRPC拒绝的url参数:

However when I run this code, I get one of two responses: if I leave mtype as GET, then jqGrid tries to pass url parameters which are rejected by ProtoRPC:

http://localhost:8084/postservice.get_tasks?_search=false&nd=1304325960695&rows=10&page=1&sidx=folder&sord=desc
400 unrecognized RPC format

如果我将mtype更改为POST,那么我将获得200 OK响应,但是网格中没有数据,并且使用Firebug,我看不到任何证据表明已返回任何数据.

If I change mtype to POST then I have a 200 OK response, but no data in my grid, and using Firebug I can't see any evidence that any data was returned.

我尝试了一些事情,但是我已经达到了我的能力极限(不难!),我将不胜感激.

I have a few things that I've tried, but I have reached the limit of my skills here (not hard!) and I'd appreciate any help.

  • 我是否需要获取ProtoRPC才能返回JsonReader默认期望的其他信息,即总计,页面,记录等?
  • 我试图遵循 Oleg's答案,但是当我将建议的代码放在jqGrid设置的前面时,我遇到了语法错误,并且请求从未运行:
  • do I need to get ProtoRPC to return the other information that JsonReader expects by default, i.e. total, page, records etc?
  • I tried to follow Oleg's answer , but when I placed the suggested code just in front of the jqGrid settings I had syntax errors and the request never ran:

$.extend($.jgrid.defaults, 数据类型:"json", {ajaxGridOptions:{contentType:"application/json"}, {ajaxRowOptions:{contentType:"application/json",类型:"PUT"} });

$.extend($.jgrid.defaults, datatype: 'json', {ajaxGridOptions: { contentType: "application/json" }, {ajaxRowOptions: { contentType: "application/json", type: "PUT" } });

  • 我只是尝试向jqGrid选项添加contentType:"application/json"(无知是幸福),但这没什么作用
  • 也许我可以找回信息,但是我只是在Firebug中看不到它?

任何帮助将不胜感激.

PS:只要不尝试发布任何数据,就可以使用curl来返回预期的数据:

PS: Using curl, I am able to return the expected data, so long as I don't try to post any data:

C:\ Users \ Staples1> curl -i -X POST -HContent-Type:application/json -HAccept:application/json C:\ Users \ Staples1>

C:\Users\Staples1>curl -i -X POST -HContent-Type:application/json -HAccept:application/json http://localhost:8084/postservice.get_tasks
HTTP/1.0 200 OK Server:
Development/1.0 Date: Mon, 02 May 2011
16:55:19 GMT Cache-Control: no-cache
Content-Type: application/json
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Content-Length: 1069
{"rows": [{"status": "Planning", "folder": "HPM", "context": "WORK", "title": "P URSUE HPM ACTIONS"}, {"status": "Planning", "folder": "PLANNED MAINTENANCE", "co ntext": "WORK", "title": "PM ASBESTOS"}, {"status": "Next Action", "folder": "PL ANNED MAINTENANCE", "context": "WORK", "title": "Chase Brian on asbestos"}, {"st atus": "Undefined", "folder": "PLANNED MAINTENANCE", "context": "WORK", "title": "PM GAS"}, {"status": "Hold", "folder": "PLANNED MAINTENANCE", "context": "WORK ", "title": "Do PBS detail for Gas"}, {"status": "Hold", "folder": "PLANNED MAIN TENANCE", "context": "WORK", "title": "Do next Product Description for Gas Servi cing"}, {"status": "Hold", "folder": "DPA", "context": "WORK", "title": "Put sam ple privacy notices on Rosie"}, {"status": "Hold", "folder": "DPA", "context": " WORK", "title": "Customer Profiling Info"}, {"status": "Hold", "folder": "DPA", "context": "WORK", "title": "Write network access agreement for contractors/ thi rd parties"}, {"status": "Hold", "folder": "DPA", "context": "WORK", "title": "C ontact CMBC for agreement"}]}
C:\Users\Staples1>

是的,我确实从Staples购买了笔记本电脑!

And yes, I did buy the laptop from Staples!

PPS:问题现在还在继续.

PPS: the problem is moving on now.

我终于再次阅读了Oleg的回复,并将其添加到jqGrid选项中:

I finally read Oleg's response again and added to the jqGrid options:

ajaxGridOptions:{contentType: 'application/json; charset = utf-8'},

ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },

现在我可以从Firebug中看到,我最终将ContentType:application/json发送到ProtoRPC,并且收到与尝试使用curl发送任何数据时得到的错误响应相同的信息,即从AppEngine进行回溯完成

Now I can see from Firebug that I am eventually sending ContentType:application/json to ProtoRPC, and I'm getting the same error response back that I get when I try to send any data using curl, namely a traceback from AppEngine which finishes

文件"C:\ Program Files (x86)\ Google \ google_appengine \ lib \ simplejson \ simplejson \ decoder.py, 解码中的第315行
obj,end = self.raw_decode(s,idx = _w(s,0).end())文件"C:\ Program 档案文件 (x86)\ Google \ google_appengine \ lib \ simplejson \ simplejson \ decoder.py, raw_decode
中的第333行 引发ValueError(无法解码JSON对象")ValueError:没有JSON 对象可以被解码

File "C:\Program Files (x86)\Google\google_appengine\lib\simplejson\simplejson\decoder.py", line 315, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Program Files (x86)\Google\google_appengine\lib\simplejson\simplejson\decoder.py", line 333, in raw_decode
raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded

从Firebug中发布的数据是

From Firebug the posted data is

_search = false& nd = 1304360758388& rows = 10& page = 1& sidx = folder& sord = desc

_search=false&nd=1304360758388&rows=10&page=1&sidx=folder&sord=desc

似乎不是特别的jsonic.看起来唯一的障碍是如何使jqGrid不发送数据,不发送某些格式正确的JSON数据,如何使ProtoRPC忽略数据?

which doesn't seem particularly jsonic. Looks like the only hurdle is how to get jqGrid to send no data, or some properly formatted JSON data, or get ProtoRPC to ignore the data?

建议!

推荐答案

它并不漂亮,也不会赢得任何奖项,但是我发现您可以关闭jqGrid尝试发送到的参数通过在网格选项中将默认值设置为null来实现ProtoRPC:

Well it's not pretty, and it won't win any prizes, but I've found that you can turn off the parameters that jqGrid is trying to send to ProtoRPC, by setting the defaults to null in the grid options:

prmNames: {nd:null, search:null, rows:null, page:null, sort:null, order:null},

现在它正在填充网格.终于,我到了起跑线.

And now it's populating the grid. Finally I've got to the starting line.

回顾一下,难题的其他方面

Just to recap, the other bits of the puzzle are

datatype: 'json',
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
mtype: 'POST',

猴子和打字机. .

这篇关于如何让jqGrid与Appengine的ProtoRPC一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆