jqGrid成功调用restful服务但无法显示jqGrid ui

时间:2016-01-18 01:02:02

标签: json rest jqgrid

这是RESTful数据格式

{"user":[
           {"id":"aupres","passwd":"aaa","age":45,"name":"father"},
           {"id":"hwa5383","passwd":"bbb","age":40,"name":"mother"},
           {"id":"julian","passwd":"ccc","age":15,"name":"son"}

]}

我的jqGrid客户端成功调用上述数据。下图显示了结果:

enter image description here

但是这段代码无法显示对jqGrid的响应。这是我的客户代码

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="EUC-KR">
    <title>jqGrid Test</title>
    <link rel="stylesheet" type="text/css" media="screen" href="jquery-ui.css"/>
    <link rel="stylesheet" type="text/css" media="screen" href="ui.jqgrid.css"/>
    <script type="text/javascript" src="jquery-2.2.0.min.js"></script>
    <script type="text/javascript" src="jquery.jqGrid.min.js"></script>
    </head>
    <body>
    <table id="grid"></table>
    <div id="pager"></div>
    <script type="text/javascript">
    $(document).ready(function(){

       $Grid = $("#grid");
       $Grid.jqGrid({

          mtype: "get",
          url: "/JQueryJsonWeb/rest/services/getJson/aupres",
          contentType: "text/json; charset=utf-8",
          dataType: "json",

          jsonReader : {
             root : "user"
          },
          colNames : [
             'id',
             'passwd',
             'age',
             'name'
          ],
          colModel : [
             { name : 'id',        width:40,  align:'center'},
             { name : 'passwd',    width:80,  align:'left'  },
             { name : 'age',       width:80,  align:'left'  },
             { name : 'name',      width:80,  align:'right' }
          ],
          pager : '#pager',
          rowNum : '10',

          loadComplete : onloadComplete,
          loadError : onloadError,
          gridComplete : ongridComplete
       });  

       function onloadComplete(jsonData, status) {
          console.log(jsonData) **// This method shows the above image.**
       }

       function onloadError(status) {
          console.log(status)
       }

       function ongridComplete() {
          console.log("fiished!!!");
       }
    });
    </script>
    </body>
    </html>

1 个答案:

答案 0 :(得分:0)

请阅读the comment上一个问题:

  • JavaScript是区分大小写的语言。 - *** Starting uWSGI 2.0.12 (64bit) on [Mon Jan 18 05:36:25 2016] *** - compiled with version: 4.8.4 on 18 January 2016 04:10:30 - os: Linux-3.13.0-48-generic #80-Ubuntu SMP Thu Mar 12 11:16:15 UTC 2015 - nodename: ip-172-31-55-58 - machine: x86_64 - clock source: unix - detected number of CPU cores: 1 - current working directory: /var/www/carzumer_api - detected binary path: /usr/local/bin/uwsgi - !!! no internal routing support, rebuild with pcre support !!! - setgid() to 33 - setuid() to 33 - chdir() to /var/www/carzumer_api/src/ - your processes number limit is 7862 - limiting address space of processes... - your process address space limit is 134217728 bytes (128 MB) - your memory page size is 4096 bytes - *** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers *** - detected max file descriptor number: 1024 - lock engine: pthread robust mutexes - thunder lock: disabled (you can enable it with --thunder-lock) - uwsgi socket 0 bound to UNIX address /var/www/carzumer_api/run/uwsgi.sock fd 6 - Python version: 2.7.6 (default, Jun 22 2015, 18:01:27) [GCC 4.8.2] - Set PythonHome to /var/www/carzumer_api/env - *** Python threads support is disabled. You can enable it with --enable-threads *** - Python main interpreter initialized at 0x2047200 - your server socket listen backlog is limited to 100 connections - your mercy for graceful operations on workers is 60 seconds - mapped 363840 bytes (355 KB) for 4 cores - *** Operational MODE: preforking *** Traceback (most recent call last): File "./carzumer_api/wsgi.py", line 16, in <module> application = get_wsgi_application() File "/var/www/carzumer_api/env/local/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application django.setup() File "/var/www/carzumer_api/env/local/lib/python2.7/site-packages/django/__init__.py", line 18, in setup apps.populate(settings.INSTALLED_APPS) File "/var/www/carzumer_api/env/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate app_config.import_models(all_models) File "/var/www/carzumer_api/env/local/lib/python2.7/site-packages/django/apps/config.py", line 198, in import_models self.models_module = import_module(models_module_name) File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) File "/var/www/carzumer_api/env/local/lib/python2.7/site-packages/django/contrib/auth/models.py", line 41, in <module> class Permission(models.Model): File "/var/www/carzumer_api/env/local/lib/python2.7/site-packages/django/db/models/base.py", line 139, in __new__ new_class.add_to_class('_meta', Options(meta, **kwargs)) File "/var/www/carzumer_api/env/local/lib/python2.7/site-packages/django/db/models/base.py", line 324, in add_to_class value.contribute_to_class(cls, name) File "/var/www/carzumer_api/env/local/lib/python2.7/site-packages/django/db/models/options.py", line 250, in contribute_to_class self.db_table = truncate_name(self.db_table, connection.ops.max_name_length()) File "/var/www/carzumer_api/env/local/lib/python2.7/site-packages/django/db/__init__.py", line 36, in __getattr__ return getattr(connections[DEFAULT_DB_ALIAS], item) File "/var/www/carzumer_api/env/local/lib/python2.7/site-packages/django/db/utils.py", line 240, in __getitem__ backend = load_backend(db['ENGINE']) File "/var/www/carzumer_api/env/local/lib/python2.7/site-packages/django/db/utils.py", line 111, in load_backend return import_module('%s.base' % backend_name) File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) File "/var/www/carzumer_api/env/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 24, in <module> raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: libgpg-error.so.0: failed to map segment from shared object: Cannot allocate memory - unable to load app 0 (mountpoint='') (callable not found or import error) - *** no app loaded. going in full dynamic mode *** - *** uWSGI is running in multiple interpreter mode *** - spawned uWSGI master process (pid: 11351) - spawned uWSGI worker 1 (pid: 11354, cores: 1) - spawned uWSGI worker 2 (pid: 11355, cores: 1) - --- no python application found, check your startup logs for errors --- {address space usage: 81760256 bytes/77MB} {rss usage: 21651456 bytes/20MB} [pid: 11355|app: -1|req: -1/1] 127.0.0.1 () {32 vars in 351 bytes} [Mon Jan 18 05:37:50 2016] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 82 bytes (0 switches on core 0) 参数将使用默认dataType: "json"
  • 也会忽略不存在的参数datatype: "xml"。如果将其解释为XML数据,则返回错误。
  • 您包含的输出来自contentType而非来自onloadErroronloadComplete的参数为onloadErrorjqXHRtextStatus。您包含了jqXHR对象的控制台输出。见the answer
  • 您应该在JavaScript中声明变量:使用errorThrown代替var $Grid = $("#grid");。在顶部函数的开头包含$Grid = $("#grid");指令有助于检测此类错误(请参阅here)。同样地,我建议您在每个语句后添加分号(请参阅"use strict"console.log(status))。
  • 您应该在所有问题中包含您使用的jqGrid版本以及哪个fork(free jqGrid - 我的fork,商业Guriddo jqGrid JS或版本中的旧jqGrid&lt; = 4.7)。叉子的可能性将越来越不同。因此,使用(或可以使用)哪一个很重要。