【发布时间】:2011-09-01 04:02:44
【问题描述】:
我正在尝试使用 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')
});
那么这里是我的配料.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');
}
}
是我遗漏了什么还是我的代码有误?我将衷心感谢您的帮助。提前致谢。
【问题讨论】:
-
不执行成功部分,只执行失败部分。没有控制台错误。我可以看到显示“失败”的警告框。
-
我想你的意思是
error: function(xhr, status, error) { alert(error) },没有failure选项,说failure: alert('fail')会立即执行alert()。 -
我明白了。感谢那。我没有错误,但我尝试删除的数据仍然无法正常执行。 :(
-
.ajax() 部分中的类型、url 和数据是否正确?
标签: php jquery ajax codeigniter