當過我做的jQuery Ajax請求,我總是得到一個錯誤500的回報,Ajax請求都返回500錯誤
我張貼到以下網址
http://localhost/domain/index.php/my_profile/interests_music
使用此javascript,
$("#add").click(function(e){
//set some process variables, we need to get the forms action,
//and any post data it is sending appending isAjax into the params
//gives us a point in the controller to gracefully check for ajax.
var action = $(this).parent('form').attr('action');
var formData = $(this).parent('form').serialize()+"&isAjax=1";
$.ajax({
type: "POST",
url: action,
data: formData
}).done(function(msg) {
alert("Data Saved: " + msg);
});
e.preventDefault();
});
該bems是bei吳派的,
音樂=野人花園& isAjax = 1
而且PHP方法的AJAX請求這個樣子的,
public function interests_music()
{
if($this->input->post('music'))
{
$this->rest->initialize(array('server' => 'https://www.googleapis.com/freebase/v1'));
$response = $this->rest->get('mqlread?query={"type":"/music/artist","name":"' . urlencode($this->input->post('music')) . '","id":[]}');
$data['image'] = 'https://usercontent.googleapis.com/freebase/v1/image'.$response->result->id[0].'?mode=fillcrop&maxwidth=80&maxheight=80';
$data['category'] = 'music';
$data['user_id'] = $this->session->userdata('id');
$data['name'] = $this->input->post('music', TRUE);
$this->profile_model->add_interest($data);
Events::trigger('interests_music');
Events::trigger('badge_stagediver');
if($this->input->post('isAjax') == 1)
{
echo json_endcode($data);
$this->_buttons();
}
redirect('my_profile/interests');
}
else
{
show_404();
}
}
我缺少的東西,這是一個共同的問題?
錯誤500意味着服務器端錯誤。嘗試尋找錯別字和語法錯誤。嘗試調試它,而不使用AJAX。另外,嘗試使用'json_encode()'而不是手動構建JSON響應 – Joseph 2012-03-16 22:35:33
不應該使用.success回調代替.done – 2012-03-16 22:36:12
@AmritpalSingh'.success()'將與'.error()'一起被棄用,並且'.complete()'。 http://api.jquery.com/jQuery.ajax/ – Joseph 2012-03-16 22:39:56