0

从我的 javascript 文件中,我正在调用一个间隔函数,这是代码

setInterval(function() {
  $.getJSON('/home/trackUnreadMsgs', function(result) {
    $.each(result, function(i, field) {
      var temp = "#messby" + result[i].from;
      $(temp).css("background", "grey");
      //alert('hi');

    });
  });
}, 1000),

这是被调用的函数, php 中的 trackUnreadMsgs。

public function trackUnreadMsgs() {
  $data['userData'] = $this - > session - > userdata('userData');
  $user_id = $data['userData'][0]['id'];

  $count_unread_msgs = $this - > data - > myquery("SELECT * FROM inbox WHERE `to`=".$user_id.
    " AND status='unread'");

  $count_unread_msgs = json_encode($count_unread_msgs);
  print_r($count_unread_msgs);
}

显然一切都在浏览器(Chrome)上运行良好,但这是控制台正在打印的内容:

VM2800:1 Uncaught SyntaxError: Unexpected end of input(anonymous function) @ seth_custom.js:225j @ jquery-2.1.3.min.js:2k.fireWith @ jquery-2.1.3.min.js:2x @ jquery-2.1.3.min.js:4(anonymous function) @ jquery-2.1.3.min.js:4
jquery-2.1.3.min.js:4 GET http://localhost/innov/index.php/home/trackUnreadMsgs 500 (Internal Server Error)k.cors.a.crossDomain.send @ jquery-2.1.3.min.js:4n.extend.ajax @ jquery-2.1.3.min.js:4n.(anonymous function) @ jquery-2.1.3.min.js:4n.extend.getJSON @ jquery-2.1.3.min.js:4(anonymous function) @ seth_custom.js:203
jquery-2.1.3.min.js:4 GET http://localhost/innov/index.php/home/getAllUnreadMsgs 500 (Internal Server Error)k.cors.a.crossDomain.send @ jquery-2.1.3.min.js:4n.extend.ajax @ jquery-2.1.3.min.js:4n.(anonymous function) @ jquery-2.1.3.min.js:4n.extend.getJSON @ jquery-2.1.3.min.js:4(anonymous function) @ seth_custom.js:274
jquery-2.1.3.min.js:4 GET http://localhost/innov/index.php/home/trackUnreadMsgs 500 (Internal Server Error)k.cors.a.crossDomain.send @ jquery-2.1.3.min.js:4n.extend.ajax @ jquery-2.1.3.min.js:4n.(anonymous function) @ jquery-2.1.3.min.js:4n.extend.getJSON @ jquery-2.1.3.min.js:4(anonymous function) @ seth_custom.js:203
jquery-2.1.3.min.js:4 GET http://localhost/innov/index.php/home/trackUnreadMsgs 500 (Internal Server Error)k.cors.a.crossDomain.send @ jquery-2.1.3.min.js:4n.extend.ajax @ jquery-2.1.3.min.js:4n.(anonymous function) @ jquery-2.1.3.min.js:4n.extend.getJSON @ jquery-2.1.3.min.js:4(anonymous function) @ seth_custom.js:203
VM2805:1 Uncaught SyntaxError: Unexpected end of input

我想知道,我做错了什么,为什么我会收到这个日志以及如何解决这个问题。我在 localhost Wamp 服务器上运行它。

4

1 回答 1

0

您在 AJAX 请求中设置了错误的路由。正确的路径是

$.getJSON('/innov/index.php/home/trackUnreadMsgs', function(result) { ... });

于 2016-05-02T14:08:16.707 回答