jquery / ajax代码在firefox上不起作用,但在其他浏览器上起作用

时间:2017-02-06 15:42:23

标签: javascript php jquery ajax

我的问题是这个,我创建了一个输入文本和一个按钮,就像在这张图片中一样: enter image description here

系统非常简单,你输入一个数字然后点击使用ajax在数据库中设置这个可能性。 我尝试使用Chrome,Internet Explorer 9和Edge和Firefox(51.0.1(32位))此代码,但似乎在Firefox上代码不起作用。 问题是什么问题? 这是javascript代码:

<script type="text/javascript">
                        $(document).ready(function () {

                            $("#set_image_pos_btn<?php echo $image->id; ?>").click(function () {
                                event.preventDefault();

                                var image_id = <?php echo $image->id; ?>;
                                var image_position = $("#image_position_value<?php echo $image->id; ?>").val();

                                $.ajax({
                                    url: '<?php echo base_url("image/pozitie"); ?>',
                                    data: {id: image_id, position: image_position},
                                    type: 'POST',
                                    success: function (data) {
                                        $("#image_position_value<?php echo $image->id; ?>").html(data);
                                    }
                                });

                            });

                        });
                    </script>

这是php代码:

function pozitie() {
    $id = $this->input->post('id');
    $position = $this->input->post('position');

    if(isset($id)) {

        $update = $this->image_model->_update($id, array('position' => $position));

        if($update) {
            $image = $this->image_model->get_where_row('id', $id);
            echo $image->position;
        } else {
            echo "eroare";
        }


    }
}

1 个答案:

答案 0 :(得分:2)

将e参数添加到click事件中,然后它将起作用。

click(function (e) {

另外:你应该关心错误处理。

var jqxhr = $.ajax( "example.php" )
.done(function() {
  alert( "success" );
})
.fail(function() {
  alert( "error" );
})
.always(function() {
  alert( "complete" );
});
相关问题