我想使用jquery ajax刪除一些數據,特別是配方的成分,我使用CodeIgniter框架,但它失敗。這裏是我的代碼的部分:正在刪除的數據不能正常工作
$(".delete").live('click',function()
{
var ri_id = $(this).attr('id');
if(confirm("Are you sure you want to delete this ingredient? Action cannot be undone."))
{
var r_id = "<?php echo $this->uri->segment(3); ?>";
alert(ri_id +" " +r_id);
$.ajax({
type: "POST",
url: "/ingredient/delete",
data: "ri_id="+ri_id +"&r_id=" +r_id,
success: function(){
$(this).parent().parent().parent().remove();
},
failure : alert('fail')
});
那麼這裏就是我爲ingredient.php:
class Ingredient extends CI_Controller {
function delete()
{
$data['ri_id']= $this->input->post('ri_id');
$data['r_id']= $this->input->post('r_id');
if (!empty($data['id']))
{
$this->load->model('ingredient_model', '', TRUE);
$this->ingredient_model->delete_recipe_ingr($data);
$this->output->set_output('works');
}
else
{
$this->output->set_output('dontwork');
}
}
}
和我的模型:
class Recipe_model extends CI_Model
{
public function delete_recipe_ingr($data)
{
$this->db->where($data);
$this->db->delete('st_recipe_ingredients');
}
}
我錯過了什麼或者是我的代碼那是錯的?我將衷心感謝您的幫助。提前致謝。
成功部分不執行,只有失敗部分。沒有控制檯錯誤。我可以看到提示框中顯示'失敗'。 – Atasha
我認爲你的意思是'error:function(xhr,status,error){alert(error)}',沒有'failure'選項並且表示'失敗:alert('fail')'將執行'alert()立即。 –
我明白了。感謝那。我沒有錯誤,但我仍然試圖刪除的數據無法正確執行。 :( – Atasha