【问题标题】:codeigniter ajax not working.Tried whatever I couldcodeigniter ajax 不工作。尽我所能
【发布时间】:2014-05-17 15:22:59
【问题描述】:

我有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 为空白 我已经尽力了,但它不起作用。请帮助我找到解决方案

【问题讨论】:

标签: php jquery html ajax codeigniter


【解决方案1】:

可能的解决方案

http://localhost/partner/app/UserController/verifyUser 直接在浏览器中使用这个 url 来检查 url 是否正确并检查输出是什么?

如果你想要的输出即将到来或没有

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);
            }
     });
    }

【讨论】:

  • 是的,当我转到此 URL 时,输出即将到来。
  • 我收到空白警报 yyaar :(
  • 我正在尝试你的代码..你是对的,我没有调用 ajax 函数,对不起,我错过了问题中的那部分对不起
  • 顺便说一句,当我使用你的代码时,我收到了两个警报..都是空白警报
  • 我得到的内容为“Hghh766”,这是我提醒它时变量内容的值
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-09
  • 2015-06-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多