PHP和AJAX - 内部错误500 [英] PHP and AJAX - internal error 500

查看:94
本文介绍了PHP和AJAX - 内部错误500的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在PHP中进行简单的AJAX调用,并且遇到内部错误500 的问题。当我点击链接时,数据成功加载 - 这是我通过FireBug看到的,但是我得到了上述错误。它在本地主机上。
当我尝试设置浏览器的地址时,这个地址被AJAX调用,所以内容被成功载入。



我应该从哪里开始搜索问题 - 或者可能出错?



编辑:在apache日志中没有什么奇怪的,看起来不错。 解决方案

如果在检查完你的php错误日志后,你没有发现任何问题,是否可以将你的javascript AJAX调用期望的结果以JSON的特定格式返回?



如果是这种情况,您需要PHP在响应AJAX调用时设置正确的内容类型标题,如下所示:

  header('Content-type:application / json'); 

所以在上下文中,这可能看起来像这样:

  $ some_data = array(
'user_id'=> 47,
'first_name'=>'Mike',
);

header('Content-type:application / json');
echo json_encode($ some_data);


I am trying to make a simple AJAX calling in PHP and have a problem with Internal error 500. When I click on the link, so the data are successfully loaded - this I see through FireBug, but I got the error above. It's on localhost. When I try to set to the URL of a browser the address, that is called by AJAX, so the content is successfully loaded.

Where I should start to search the problem - or what could be wrong?

EDIT: in apache log is nothing weird, looks fine.

解决方案

If after checking your php error log you don't find any issues, could it be your javascript AJAX call expects results to be returned in a specific format like JSON?

If this is the case, you need PHP to set the correct content type header when it is responding to the AJAX call, like so:

header('Content-type: application/json');

So in context, this might look something like:

$some_data = array(
  'user_id' => 47,
  'first_name' => 'Mike',
);

header('Content-type: application/json');
echo json_encode($some_data);

这篇关于PHP和AJAX - 内部错误500的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆