我是新來的ajax,我只是嘗試了一些Ajax的例子,但我不斷收到這500內部服務器錯誤。我正在通過網絡尋找解決方案,但似乎沒有任何工作。但是,如果我將POST類型更改爲GET,它工作正常。Ajax POST給500內部服務器錯誤
控制器:
<?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.
螢火顯示錯誤:
POST http://localhost/ias/testingAjax/getSomething
500 Internal Server Error
30ms
你沒有任何形式,你的AJAX沒有向服務器發送任何東西。 –
表單不是問題,但問題是至少你必須發送一些東西到服務器,這不是在你的代碼中發生。 –
我做了一些編輯,現在我有一些數據發送到服務器,但它仍然無法正常工作。 – John