500内部服务器错误,ajax,setInterval

时间:2016-05-02 14:06:43

标签: javascript php ajax http-status-code-500

从我的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服务器上运行它。

1 个答案:

答案 0 :(得分:0)

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

  

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