【问题标题】:500 Internal Server Error , ajax , setInterval500 内部服务器错误,ajax,setInterval
【发布时间】:2016-08-27 08:06:09
【问题描述】:

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

【问题讨论】:

  • “500 内部服务器错误” - 检查您的日志。
  • }, 1000),
  • 请不要使用这个标签。对你的问题进行分类是没有意义的。根据你添加它时当然已经阅读的标签描述。

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


【解决方案1】:

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

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

【讨论】:

  • 我使用的是codeigniter,访问php控制器函数的协议是controllerName/functionName。
  • 因此您应该在 codeigniter 中编辑您的设置或硬编码系统进行 Ajax 调用的主机,因为根路径错误
猜你喜欢
  • 2013-05-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-12
  • 2020-02-12
  • 2014-09-24
  • 2018-08-09
  • 1970-01-01
相关资源
最近更新 更多