gpt4 book ai didi

javascript - 我的编辑按钮 ajax 不工作

转载 作者:行者123 更新时间:2023-11-28 00:53:55 25 4
gpt4 key购买 nike

我的编辑按钮位于用户可以编辑的模态中。但是,更新部分不起作用。我觉得问题出在我的 Controller 部分,但到目前为止我似乎无法自行解决。

ajax 的开发人员控制台中的响应是 (0),或者当我从 Controller 使用 var_dump($data) 时,响应是一个数组。我不知道发生了什么事。谁能帮我?我已经这样做了将近 3 天。我只是跳过并转到另一个模块。但我现在需要完成它..

Ajax代码

 $("#form2").submit(function(e) {

var supp_code = $('#supp_codev1').val();
var address1 = $('#address1v1').val();
var address2 = $('#address2v1').val();
var country = $('#countryv1').val();
var description = $('#descriptionv1').val();
var tel_num = $('#tel_numv1').val();
var fax_num = $('#fax_numv1').val();
var contact_person = $('#contact_personv1').val();
var email = $('#emailv1').val();
var consol_agent = $('#consol_agentv1').val();
var disc1 = $('#disc1v1').val();
var disc2 = $('#disc2v1').val();
var disc3 = $('#disc3v1').val();
var disc4 = $('#disc4v1').val();
var disc5 = $('#disc5v1').val();
var last_transaction = $('#last_transactionv1').val();
var old_supplier = $('#old_supplierv1').val();

var sfm_table = $('#datatable-buttons').DataTable();
e.preventDefault();
$.ajax({


url: '<?php echo base_url(); ?>SFM/update',
method: 'POST',
dataType: 'JSON',

data: {
'supp_codev1': supp_code,
'address1': address1,
'address2': address2,
'country': country,
'description': description,
'tel_num': tel_num,
'fax_num': fax_num,
'contact_person': contact_person,
'email': email,
'consol_agent': consol_agent,
'disc1': disc1,
'disc2': disc2,
'disc3': disc3,
'disc4': disc4,
'disc5': disc5,
'last_transaction': last_transaction,
'old_supplier': old_supplier

},



success: function(data) {

console.log(data);

if (data) {

$("#sfm_modal_edit").modal('hide');

swal("Data Edited", {
icon: "success"
});


} else {

swal("Error", {
icon: "error"
});
}
}
});

});

用于填充表单的 Ajax

  $(document).on("click", ".editBtn", function() {

var rowID = $(this).attr('id');

$.ajax({
url: '<?php echo base_url(); ?>SFM/fetch',

method: "POST",
dataType: "json",
data: {
'id': rowID
},

success: function(data) {




$('#supp_codev1').val(data.fo_supp[0].SUPP_CODE);
$('#address1v1').val(data.fo_supp[0].ADDRESS);
$('#address2v1').val(data.fo_supp[0].ADDRESS2);
$('#countryv1').val(data.fo_supp[0].COUNTRY);
$('#descriptionv1').val(data.fo_supp[0].DESCRIPTION);
$('#tel_numv1').val(data.fo_supp[0].TEL_NO);
$('#fax_numv1').val(data.fo_supp[0].FAX_NO);
$('#contact_personv1').val(data.fo_supp[0].CONTACT);
$('#emailv1').val(data.fo_supp[0].EMAIL);
$('#consol_agentv1').val(data.fo_supp[0].CONS_AGENT);
$('#disc1v1').val(data.fo_supp[0].DISC1);
$('#disc2v1').val(data.fo_supp[0].DISC2);
$('#disc3v1').val(data.fo_supp[0].DISC3);
$('#disc4v1').val(data.fo_supp[0].DISC4);
$('#disc5v1').val(data.fo_supp[0].DISC5);
$('#last_transactionv1').val(data.fo_supp[0].LAST_TRANS);
$('#old_supplierv1').val(data.fo_supp[0].SUPP_CODE2);




}
});

});

Controller

	function update()
{
$data = array(
'SUPP_CODE'=> $this->input->post('supp_codev1'),
'ADDRESS'=> $this->input->post('address1'),
'ADDRESS2'=> $this->input->post('address2'),
'COUNTRY'=> $this->input->post('country'),
'DESCRIPTION'=> $this->input>post('description'),
'TEL_NO'=> $this->input->post('tel_num'),
'FAX_NO'=> $this->input->post('fax_num'),
'CONTACT'=> $this->input->post('contact_person'),
'EMAIL'=> $this->input->post('email'),
'CONS_AGENT'=> $this->input>post('consol_agent'),
'DISC1'=> $this->input->post('disc1'),
'DISC2'=> $this->input->post('disc2'),
'DISC3'=> $this->input->post('disc3'),
'DISC4'=> $this->input->post('disc4'),
'DISC5'=> $this->input->post('disc5'),
'LAST_TRANS'=> $this->input- >post('last_transaction'),
'SUPP_CODE2'=> $this->input->post('old_supplier')
);

$supp = $this->input->post('supp_codev1');

$insertReturn2 = $this->system_model->update('fo_supp', $supp ,$data);

echo json_encode($insertReturn2);

}

查看

 <!--MODAL HERE-->
<div class="modal fade" name="sfm_modal_edit " id="sfm_modal_edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
<span aria-hidden="true">×</span>
<span class="sr-only">Close</span>
</button>
<h4 class="modal-title" id="myModalLabel">
Edit Supplier
</h4>
</div>
<!-- Modal Body -->
<div class="modal-body">
<form id="form2" class="form-horizontal">
<div class="form-group form-group-sm">
<!-- left column -->
<div class="col-sm-6">
<div class="form-group">
<label for="new_name" class="col-sm-2 control-label bg-danger" style="visibility: hidden;">Supplier Code</label>
<span class="label label-default">Supplier Code</span>
<div class="col-sm-10">
<input type="text" name="supp_codev1" id="supp_codev1" class="form-control" data-inputmask="'mask': '999999'">
</div>
</div>
<div class="form-group">
<label for="new_subname" class="col-sm-2 control-label" style="visibility: hidden;">Address</label>
<span class="label label-default">Address</span>
<div class="col-sm-10">
<input type="text" name="address1v1" class="form-control col-md-10" id="address1v1" placeholder="">
</div>
</div>
<div class="form-group">
<label for="new_address" class="col-sm-2 control-label bg-danger" style="visibility: hidden;">Address 2</label>
<span class="label label-default">Address 2</span>
<div class="col-sm-10">
<input type="text" name="address2v1" class="form-control col-md-10" id="address2v1" placeholder="">
</div>
</div>
<div class="form-group">
<label for="new_addresssub" class="col-sm-2 control-label" style="visibility: hidden;">Country</label>
<span class="label label-default">Country</span>
<div class="col-sm-10">
<input type="text" name="countryv1" id="countryv1" class="form-control col-md-10" />
</div>
</div>
<!-- <div class="form-group"><label for="new_zip" class="col-sm-2 control-label bg-danger" style = "visibility: hidden;">Description</label><span class="label label-default" >Supplier Code</span><div class="col-sm-3"><input type="text" class="form-control" id="new_zip" placeholder=""></div><div class="col-sm-7"><label for="new_zip_detail" class="sr-only" style = "visibility: hidden;">City, State Country</label><input type="text" class="form-control" id="new_zip_detail" placeholder="City, State Country" disabled=""></div></div> -->
<div class="form-group">
<label for="new_addresssub" class="col-sm-2 control-label" style="visibility: hidden;">Description</label>
<span class="label label-default">Description</span>
<div class="col-sm-10">
<input type="text" name="descriptionv1" class="form-control" id="descriptionv1" placeholder="">
</div>
</div>
<div class="form-group">
<label for="new_phone" class="col-sm-2 control-label" style="visibility: hidden;">Telephone Number</label>
<span class="label label-default">Telephone Number</span>
<div class="col-sm-10">
<input type="text" class="form-control" name="tel_numv1" id="tel_numv1" data-inputmask="'mask' : '(999) 999-9999'">
</div>
</div>
<div class="form-group">
<label for="new_phone" class="col-sm-2 control-label" style="visibility: hidden;">Fax Number</label>
<span class="label label-default">Fax Number</span>
<div class="col-sm-10">
<input type="text" class="form-control" name="fax_numv1" id="fax_numv1" data-inputmask="'mask' : '(999) 999-9999'">
</div>
</div>
<div class="form-group">
<label for="new_name" class="col-sm-2 control-label bg-danger" style="visibility: hidden;">Consolidating Agent</label>
<span class="label label-default">Consolidating Agent</span>
<div class="col-sm-10">
<input type="text" name="consol_agentv1" class="form-control" id="consol_agentv1" placeholder="">
</div>
</div>

</div>
<!-- right column -->
<div class="col-sm-6">
<div class="form-group">
<label for="new_subname" class="col-sm-2 control-label" style="visibility: hidden;">Email</label>
<span class="label label-default">Email</span>
<div class="col-sm-10">
<input type="text" class="form-control" name="emailv1" id="emailv1" placeholder="">
</div>
</div>
<div class="form-group">
<label for="new_name" class="col-sm-2 control-label bg-danger" style="visibility: hidden;">Contact Person</label>
<span class="label label-default">Contact Person</span>
<div class="col-sm-10">
<input type="text" class="form-control" name="contact_personv1" id="contact_personv1" placeholder="">
</div>
</div>

<div class="form-group">
<label for="new_subname" class="col-sm-2 control-label" style="visibility: hidden;">Discount 1</label>
<span class="label label-default">Discount 1</span>
<div class="col-sm-10">
<input type="text" class="form-control" name="disc1v1" id="disc1v1" placeholder="">
</div>
</div>
<div class="form-group">
<label for="new_address" class="col-sm-2 control-label bg-danger" style="visibility: hidden;">Discount 2</label>
<span class="label label-default">Discount 2</span>
<div class="col-sm-10">
<input type="text" class="form-control" name="disc2v1" id="disc2v1" placeholder="">
</div>
</div>
<div class="form-group">
<label for="new_addresssub" class="col-sm-2 control-label" style="visibility: hidden;">Discount 3</label>
<span class="label label-default">Discount 3</span>
<div class="col-sm-10">
<input type="text" class="form-control" name="disc3v1" id="disc3v1" placeholder="">
</div>
</div>

<div class="form-group">
<label for="new_phone" class="col-sm-2 control-label" style="visibility: hidden;">Discount 4</label>
<span class="label label-default">Discount 4</span>
<div class="col-sm-10">
<input type="phone" class="form-control" name="disc4v1" id="disc4v1" placeholder="">
</div>
</div>
<div class="form-group">
<label for="new_phone" class="col-sm-2 control-label" style="visibility: hidden;">Discount 5</label>
<span class="label label-default">Discount 5</span>
<div class="col-sm-10">
<input type="phone" class="form-control" name="disc5v1" id="disc5v1" placeholder="">
</div>
</div>
<div class="form-group">
<label for="new_phone" class="col-sm-2 control-label" style="visibility: hidden;">Last Transaction</label>
<span class="label label-default">Last Transaction</span>
<div class="col-sm-10">
<input type="text" class="form-control" name="last_transactionv1" id="last_transactionv1" data-inputmask="'mask': '9999/99/99'">
</div>
</div>
<div class="form-group">
<label for="new_phone" class="col-sm-2 control-label" style="visibility: hidden;">Old Supplier</label>
<span class="label label-default">Old Supplier</span>
<div class="col-sm-10">
<input type="phone" class="form-control" name="old_supplierv1" id="old_supplierv1" placeholder="">
</div>
</div>

</div>
</div>

</div>
<!-- End main input boxes, starting a new "row" -->
<!-- Modal Footer -->
<div class="modal-footer">

<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" >Edit</button>
</div>
<!-- End Modal Footer -->
</form>
</div>
<!-- End modal body div -->
</div>
<!-- End modal content div -->
</div>
<!-- End modal dialog div -->
</div>
<!-- End modal div -->

最佳答案

未找到名为“editBtn”的对象类

您是否在文档中创建“editBtn”对象?

关于javascript - 我的编辑按钮 ajax 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53077505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com