必承其重 | 欲带皇冠 2013-07-15 15:50 采纳率: 0%
浏览 2

非确定性解析器错误

I encountered some weird error by doing some short-polling ajax()-request to a play2.1-server.

Currently I am using REST to send a request to the server and I await a json as answer. The server always response the correct JsonP but after a short time the client gets a "parsererror" and stops calling the ajax-callbackmethod for all following requests.

The Client:

   function restGet(url, callback) {
       $.ajax({
          type: 'GET',
          url: 'www. ... /getQuestions/42',
          dataType: 'jsonp',
          jsonpCallback: 'callbackMethod',
          success: 'callbackMethod',
          error: function (jqXHR, status, exception) {
              console.log('jqXHR: ' + JSON.stringify(jqXHR));
              console.log('restGet error: ' + status + ' - ' + exception);
          }
      });
   }


  function callbackMethod(response) {
       console.log('At callbackMethod(' + JSON.stringify(response) + ')');

  }

The Server:

    public static Result getQuestions(String lectureId) {
        String callbackMethod = request().getQueryString("callback");
        String json = "{\"question\":\"Do you find my error?\"}";
        return ok((callback == null)?json:callback + "("+ json + ")");
    }

According to Fiddler Web Debugger the server always sends the same (and correct) jsonp-string. And the restGet-Method from the client is called every second.

The client prints out the following as soon as it crashes:

[17:46:24.036] jqXHR: {"readyState":4,"status":200,"statusText":"success"}

[17:46:24.036] restGet error: parsererror - Error: callbackMethod was not called

I don't know what's wrong with my code and the other posts I found about parsererror always said you have to use jsonp instead of json. That's what I did, didn't I?

  • 写回答

1条回答 默认 最新

  • weixin_33697898 2013-07-15 15:53
    关注

    Function names should not be quoted.

       function restGet(url, callback) {
           $.ajax({
              type: 'GET',
              url: 'www. ... /getQuestions/42',
              dataType: 'jsonp',
              jsonpCallback: 'callbackMethod',
              success: callbackMethod,
              error: function (jqXHR, status, exception) {
                  console.log('jqXHR: ' + JSON.stringify(jqXHR));
                  console.log('restGet error: ' + status + ' - ' + exception);
              }
          });
       }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据