如何在不使用按钮的情况下为 php 代码发送数据:提交(使用标签 <a href=""></a>
),因为在它转到 href 并将 $query 行放入 html 代码中进行更新?
(我的意思是,在选中复选框并单击标签中的链接后,将带有 jquery 代码的值发送到 php 代码,然后转到链接标签 a 进行更新)(我不想在标签形式中使用 action
,因为我使用了多个action
的 url ) 如何解决?
HTML:
<a href="<?= base_url()?>submits/guide_update" class="guide_update" id="edit_icon"></a>
<form class="ser_form" method="post">
<input type="checkbox" name="checked[]" value="2">
</form>
PHP:
function guide_update(){
$update = $this -> input -> post('checked');
var_dump($update);
if (is_array($update) && count($update) > 0) {
foreach($update as $val){
$data['query'] = $this->db->get_where('guide', array('id' => $val))->row();
}
$this -> load -> view('admin/submits/guide_update', $data);
}
}
jQuery:
$('#edit_icon').click(function(){
var result = true;
var size_check = $(':checkbox:checked').size();
//alert(size_check);
if(size_check > 1){
$('#message').hide().fadeIn('slow').html('<div id="error_text" style="background-color: #ffffd9; border: 1px solid #d2d200;">You're allowed to edit a row.<div>');
$('#error_text').delay(7000).fadeOut('slow');
result = false;
}if(size_check == 0){
//alert('no')
$('#message').hide().fadeIn('slow').html('<div id="error_text" style="background-color: #ffffd9; border: 1px solid #d2d200;">You did not select any row for editing.<div>');
$('#error_text').delay(7000).fadeOut('slow');
result = false;
}
return result
})
最佳答案
使用 JQuery.serialize序列化表单数据的函数,然后您可以使用 AJAX 将其发送到服务器。
关于php - 使用 jQuery 发送表单数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7713821/