codeigniter ajax没有工作。尽我所能

时间:2014-05-17 06:11:18

标签: php jquery html ajax codeigniter

我有ajax功能

$('a[name=deleteButton]').on('click', function () {
    arr=[];
    var arr = $("input[name='post[]']:checked").map(function() { 
            return this.value; 
          }).get();
          var content = $(this).parents('tr').find('.key').html();
          alert(content);
});

function makeAjaxCall(){
    $.ajax({
        type: "post",
        url: "http://localhost/partner/app/UserController/verifyUser",
        cache: false,               
        data: {id : content},
        success: function(data){                        
                alert('hi');
        },
        error: function(td){                        
            alert(td.responseText);
        }
 });
}

控制器是

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class UserController extends CI_Controller {

    public function verifyUser()    {

        $status = array("STATUS"=>"false");

        echo json_encode ($status) ;    
    }
}

视图是

<tr>
                                <td><input type='checkbox' name='post[]' value="<?php echo ++$i; ?>"></td>
                                <td><?php echo date('d-M-Y', strtotime($row['connct_CreationTime']));?></td>
                                <td><?php echo $row['connct_serviceName'];?></td>
                                <td><?php echo $row['connct_websiteUrl'];?></td>
                                <td class="key"><?php echo $row['connct_passKey'];?></td>
                                <td><?php echo $row['responseURL'];?></td>
                                <td><a name="deleteButton"  href=""><i class="icon-remove text-danger"></i></a></td>
                                <!-- <td align='center' width='30'><a data-toggle='modal' href='#' ><i class='icon-remove text-danger'></i></a></td> -->
                            </tr>

var内容正在收到警报。但是在网络选项卡中,它显示的ajax POST被取消了。 为什么这不起作用。错误,td.responseText为空 我尽我所能,但它不起作用。请帮我找到解决方案

1 个答案:

答案 0 :(得分:0)

可能的解决方案

http://localhost/partner/app/UserController/verifyUser直接在浏览器中使用此网址来检查网址是否正确,还检查输出结果是什么?

如果您想要的输出即将到来

<强> EIDTED

从我的观点来看,你的代码应该是这样的

    $('a[name=deleteButton]').on('click', function () {
        arr=[];
        var arr = $("input[name='post[]']:checked").map(function() { 
                return this.value; 
              }).get();
              var content = $(this).parents('tr').find('.key').html();
              makeAjaxCall(content);
             return false;
    });

    function makeAjaxCall(content){
        $.ajax({
            type: "post",
            url: "http://localhost/partner/app/UserController/verifyUser",
            cache: false,               
            data: {id : content},
            success: function(data){                        
                    alert('hi');
            },
            error: function(td){                        
                alert(td.responseText);
            }
     });
    }