【问题标题】:How to fix undefined url using JQuery in Codeigniter如何在 Codeigniter 中使用 JQuery 修复未定义的 url
【发布时间】:2021-09-30 05:35:15
【问题描述】:

我在我的codeigniter项目中使用sweetalert2有问题,错误是当我点击按钮确认删除时,按钮无法获取所有的url,所以页面显示404错误页面,如何解决这个错误? 这是带有 jquery 的 javascript


    $('.remove').on('click', function (e) {
      e.preventDefault();
      const href =$(this).attr('href');
      console.log($href)
      // var getUrl = $(this).attr('href', $(e.relatedTarget).data('href'));
    
      // var baseUrl = getUrl .protocol + "//" + getUrl.host + "/" + getUrl.pathname.split('/')[1];
      Swal.fire({
        title: 'Apakah Yakin Hapus Data Ini?',
        text: "Data yang terhapus tidak dapat dikembalikan!",
        icon: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Ya, Hapus!',
        cancelButtonText: 'Tidak!'
      }).then((result) => {
        if (result.isConfirmed) {
          document.location.href = href;
          
        }
      });
    });

这是使用数据表的按钮

<td align="center" width="130px">                             
<?php
echo anchor(site_url('pegawai/read/' . $row->user_id), '<button type="button" data-toggle="modal" data-target="#exampleModal"class="btn btn-sm btn-primary" data-tooltip="tooltip" data-placement="bottom" title="detail"><i class="fa fa-eye"></i></button>');
echo ' ';
echo anchor(site_url('pegawai/update/' . $row->user_id), '<button class="btn btn-sm btn-success btn-flat" data-tooltip="tooltip" data-placement="bottom" title="edit"><i class="fa fa-edit"></i></button>');
echo ' ';
echo anchor(site_url('pegawai/delete/' . $row->user_id), '<button class="btn btn-sm btn-danger btn-flat remove" id="deletedata" data-tooltip="tooltip" data-placement="bottom" title="hapus"><i class="fa fa-trash"></i></button>');
?>
</td>

【问题讨论】:

  • and this is the button 浏览器中的按钮是什么样的(不是在屏幕上,我是指 HTML)
  • document.location.href = href,true; 看起来......错了......你知道逗号运算符在这行代码中的作用吗?
  • 我正在使用数据表和数组 php,并且我在我的 javascipt 代码中编辑了 href 逗号,你知道我获取 url 的代码有什么问题吗?
  • 按钮的 HTML 在浏览器中是什么样子的 - 不是 PHP,这不是浏览器正在获取的内容

标签: javascript php jquery codeigniter sweetalert2


【解决方案1】:

解决方案 1:

var href =$(this).parent().attr('href');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-17
    • 2019-09-27
    相关资源
    最近更新 更多