【发布时间】:2015-05-12 16:53:40
【问题描述】:
我是 ajax 新手,我只是在尝试一些 ajax 示例,但我不断收到 500 Internal Server Error。我在网上搜索解决方案,但似乎没有任何效果。但是,如果我将类型从 POST 更改为 GET,它就可以正常工作。
控制器:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class testingAjax extends CI_Controller
{
public function index()
{
$this->load->view('testingAjax_view');
}
public function getSomething()
{
$values = $this->input->post('testing');
echo $values;
}
}
js 脚本
$(document).ready(
function ()
{
$('#callBackBtn').click(function()
{
jQuery.ajax({
type: "POST",
url: "testingAjax/getSomething",
data: {testing: "testing"},
success: function(data) {
$('#responseText').val(data);
},
error: function(xhr, text_status, error_thrown){
alert(error_thrown);
}
})
});
}
);
查看
<body>
<h3>Testing Ajax</h3>
<div class="entry-wrapper">
<input type="text" id="input_text">
<input type="button" value="Ajax Call Back" id="callBackBtn"/>
</div>
<div class="response_wrapper">
<textarea id="responseText"></textarea>
</div>
</body>
我在 xammp 上运行它。以下是 apache 错误日志(不确定它们是否有用)
[Wed May 13 00:31:53.251642 2015] [core:notice] [pid 25716:tid 456] AH00094: Command line: 'c:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
[Wed May 13 00:31:53.257646 2015] [mpm_winnt:notice] [pid 25716:tid 456] AH00418: Parent: Created child process 25724
[Wed May 13 00:31:57.895294 2015] [ssl:warn] [pid 25724:tid 460] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Wed May 13 00:31:59.065692 2015] [ssl:warn] [pid 25724:tid 460] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Wed May 13 00:31:59.205786 2015] [mpm_winnt:notice] [pid 25724:tid 460] AH00354: Child: Starting 150 worker threads.
Firebug 显示错误:
POST http://localhost/ias/testingAjax/getSomething
500 Internal Server Error
30ms
【问题讨论】:
-
您没有表单,并且您的 AJAX 没有向服务器发送任何内容。
-
表单不是问题,但问题是至少你必须向服务器发送一些东西,这在你的代码中没有发生。
-
我进行了一些编辑,现在我有一些数据发送到服务器,但它仍然无法正常工作。
-
我添加了我的萤火虫显示的错误
-
@John 请为其他人的帮助标记和投票。谢谢。
标签: php jquery ajax codeigniter