renderAjax failed to return data - yii2

I did this in the past year and it works just fine. Until recently I encounter this problem which I don't know what caused it.
Here I'm trying to pass supplierID from a (1)form through (2)ajax javascript and return the (3)data from AdminController to a (4)div in the same view
(1)form:-
<?php $form = ActiveForm::begin([
'id'=>'chatform'
]);?>
<div class="box-body">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>No</th>
<th>Supplier</th>
<th>Option(s)</th>
</tr>
</thead>
<tbody>
<?php
for($x = 0; $x < count($supplierChatInfoListTable); $x++){ ?>
<tr>
<td>
<?=$x+1?>
<div class="form-group">
<input type="hidden" name="supplierID" id="supplierID" class="form-control"
value="<?=$supplierChatInfoListTable[$x]['supplierID']?>" style="width: 50px">
</div>
</td>
<td >
<h4><?=$supplierChatInfoListTable[$x]['supplierFirstname']?></h4>
</td>
<td>
<button type="button" class="btn btn-primary btnchat"><i class="fa fa-edit"></i></button>
</td>
</tr>
<?php } ?>
</tbody>
<tfoot>
<tr>
<th>No</th>
<th>Supplier</th>
<th>Option(s)</th>
</tr>
</tfoot>
</table>
</div>
<?php ActiveForm::end();?>
and here is my (2)javascript running in the same view:-
<?php
$urproudcode= Url::to(['admin/chatinfo2pass']);
$this->registerJs("
$(function(){
$('.btnchat').click(function(){
var supplierID = $('#supplierID').val();
$.ajax({
'url':'".$urproudcode."',
'data':{supplierID:supplierID},
'method':'POST',
beforeSend: function (xhr) {
$.blockUI({
message: 'Processing...',
css: {
border: 'none',
padding: '15px',
backgroundColor: '#000',
'-webkit-border-radius': '10px',
'-moz-border-radius': '10px',
opacity: .5,
color: '#fff'
}
});
},
'success':function(data){
$('.chatmessages').html('Success');
if(data == 'false'){
$.unblockUI();
$('.chatmessages').html('Data False');
}else{
$.unblockUI();
$('.chatmessages').html(data);
}
},
error: function (xhr, ajaxOptions, thrownError) {
$.unblockUI();
$('.chatmessages').html('Failed');
console.log(data);
}
});
});
});
");
?>
(3)div with class=chatmessages in the same view
<div class="col-md-8 chatmessages">
</div>
(4)actionChatinfo2pass in AdminController
public function actionChatinfo2pass()
{
$postData = \Yii::$app->request->post('supplierID');
$supplierID = intval($postData);
// fetch all supplier for chat
$supplierChatInfoListTable = SupplierProfile::find()
->select(['supplier_profileID AS supplierID','supplier_profile.first_name AS supplierFirstname',
'supplier_profile.middle_name AS supplierMiddlename', 'supplier_profile.last_name AS
supplierLastname', 'login_profile.login_profileID AS loginID', 'status_login.status_loginID AS
statusLoginID', 'status_login.description AS statusLogindesc'])
->leftJoin('login_profile', 'login_profile.login_profileID = supplier_profile.login_profile_ID')
->leftJoin('status_login', 'status_login.status_loginID = login_profile.status_login_ID')
//->where(['=', 'status_login.description', $activeSupplier])
->orderBy(['supplier_profile.supplier_profileID' => SORT_ASC])
->asArray()
->all();
$dataSend['supplierChatInfoListTable'] = $supplierChatInfoListTable;
$this->layout = 'admin/main';
$html= $this->renderAjax('#app/views/admin/displaychatmessage.php',$dataSend);
echo $html;
}
But it return the 'same' supplierID for both supplier as show below:
and browser console give me this error?(updated):-
btw, this is the content of displaychatmessage.php (I just try to display supllierID and their name)
<!-- DIRECT CHAT WARNING -->
<div class="box box-warning direct-chat direct-chat-warning">
<div class="box-header with-border">
<h3 class="box-title">Direct Chat</h3>
<div class="box-tools pull-right">
<span data-toggle="tooltip" title="3 New Messages" class="badge bg-yellow">3</span>
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
</button>
<button type="button" class="btn btn-box-tool" data-toggle="tooltip" title="Contacts" data-widget="chat-pane-toggle">
<i class="fa fa-comments"></i></button>
<button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
</div>
</div>
<!-- /.box-header -->
<div class="box-body">
<!-- Conversations are loaded here -->
<div class="direct-chat-messages">
<!-- Message. Default to the left -->
<div class="direct-chat-msg">
<div class="direct-chat-info clearfix">
<?php for($z = 0; $z < count($supplierChatInfoListTable); $z++){?>
<span class="direct-chat-name pull-left">Supplier ID: <?=$supplierChatInfoListTable[$z]['supplierID']?>, <?=$supplierChatInfoListTable[$z]['supplierFirstname']?> <?=$supplierChatInfoListTable[$z]['supplierMiddlename']?> <?=$supplierChatInfoListTable[$z]['supplierLastname']?></span>
<?php }?>
<span class="direct-chat-timestamp pull-right">23 Jan 2:00 pm</span>
</div>
<!-- /.direct-chat-info -->
<img class="direct-chat-img" src="dist/img/user1-128x128.jpg" alt="Message User Image"><!-- /.direct-chat-img -->
<div class="direct-chat-text">
Is this template really for free? That's unbelievable!
</div>
<!-- /.direct-chat-text -->
</div>
<!-- /.direct-chat-msg -->
<!-- Message to the right -->
<div class="direct-chat-msg right">
<div class="direct-chat-info clearfix">
<span class="direct-chat-name pull-right">Sarah Bullock</span>
<span class="direct-chat-timestamp pull-left">23 Jan 2:05 pm</span>
</div>
<!-- /.direct-chat-info -->
<img class="direct-chat-img" src="dist/img/user3-128x128.jpg" alt="Message User Image"><!-- /.direct-chat-img -->
<div class="direct-chat-text">
You better believe it!
</div>
<!-- /.direct-chat-text -->
</div>
<!-- /.direct-chat-msg -->
</div>
<!--/.direct-chat-messages-->
<!-- Contacts are loaded here -->
<div class="direct-chat-contacts">
<ul class="contacts-list">
<li>
<a href="#">
<img class="contacts-list-img" src="dist/img/user1-128x128.jpg" alt="User Image">
<div class="contacts-list-info">
<span class="contacts-list-name">
Count Dracula
<small class="contacts-list-date pull-right">2/28/2015</small>
</span>
<span class="contacts-list-msg">How have you been? I was...</span>
</div>
<!-- /.contacts-list-info -->
</a>
</li>
<!-- End Contact Item -->
</ul>
<!-- /.contatcts-list -->
</div>
<!-- /.direct-chat-pane -->
</div>
<!-- /.box-body -->
<div class="box-footer">
<form action="#" method="post">
<div class="input-group">
<input type="text" name="message" placeholder="Type Message ..." class="form-control">
<span class="input-group-btn">
<button type="submit" class="btn btn-warning btn-flat">Send</button>
</span>
</div>
</form>
</div>
<!-- /.box-footer-->
</div>
<!--/.direct-chat -->
Can you help me with this? I don't know where it went wrong.

As you have mentioned you are getting same supplierID on clicking both supplier. This problem is caused because in your js code you are getting supplierID by id of the input i.e '#supplierID', and according to your html code the input elements of both of the suppliers have same value in their id attribute i.e 'supplierID', because of that every time js will get value from first input element with id attribute value 'supplierID'. So you need to make some changes in your html and js code. As there is separate edit button for each supplier so instead of using input to store supplierID value you can store it in a data attribute in the edit button. So your updated html code would become
<?php $form = ActiveForm::begin([
'id'=>'chatform'
]);?>
<div class="box-body">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>No</th>
<th>Supplier</th>
<th>Option(s)</th>
</tr>
</thead>
<tbody>
<?php
for($x = 0; $x < count($supplierChatInfoListTable); $x++){
$supID = $supplierChatInfoListTable[$x]['supplierID']; ?>
<tr>
<td>
<?=$x+1?>
<div class="form-group">
<input type="hidden" name="<?='supplierID'.$supID?>" id="<?='supplierID'.$supID?>" class="form-control"
value="<?=$supID?>" style="width: 50px">
</div>
</td>
<td >
<h4><?=$supplierChatInfoListTable[$x]['supplierFirstname']?></h4>
</td>
<td>
<button type="button" class="btn btn-primary btnchat" data-supplierID="<?=$supID?>"><i class="fa fa-edit"></i></button>
</td>
</tr>
<?php } ?>
</tbody>
<tfoot>
<tr>
<th>No</th>
<th>Supplier</th>
<th>Option(s)</th>
</tr>
</tfoot>
</table>
</div>
<?php ActiveForm::end();?>
And then get the supplierID of clicked supplier from data attribute of button in js. So your js code would become
<?php
$urproudcode= Url::to(['admin/chatinfo2pass']);
$this->registerJs("
$(function(){
$('.btnchat').click(function(){
var supplierID = $(this).attr('data-supplierID');
$.ajax({
'url':'".$urproudcode."',
'data':{supplierID:supplierID},
'method':'POST',
beforeSend: function (xhr) {
$.blockUI({
message: 'Processing...',
css: {
border: 'none',
padding: '15px',
backgroundColor: '#000',
'-webkit-border-radius': '10px',
'-moz-border-radius': '10px',
opacity: .5,
color: '#fff'
}
});
},
'success':function(data){
$('.chatmessages').html('Success');
if(data == 'false'){
$.unblockUI();
$('.chatmessages').html('Data False');
}else{
$.unblockUI();
$('.chatmessages').html(data);
}
},
error: function (xhr, ajaxOptions, thrownError) {
$.unblockUI();
$('.chatmessages').html('Failed');
console.log(data);
}
});
});
});
");
?>
I hope your problem will be solved.

Related

Create a show all button to show hidden row

My code is like this: when you check the 'hide' column, the whole row is hidden. I also have a 'Show All' checkbox. When I check it, all rows (including the hidden ones) are shown. But when I uncheck it, all rows disappear. How can I make it so only the hidden rows disappear when I uncheck 'Show All', and the other rows still remain visible?
<body ng-app="myApp" ng-controller="myController">
<h1>Fruits in Vietnam</h1>
<hr>
<form name="myForm">
<div class="input-group input-group-lg">
<input type="text" class="form-control" name="mdfruitname" id="txtfruitname" ng-model="mdfruitname"
required>
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button" ng-click="addnew()"
ng-disabled="myForm.mdfruitname.$pristine || myForm.mdfruitname.$invalid">Add
</button>
</div>
</div>
</form>
</div>
<table class="table table-striped">
<thead>
<tr>
<th>Description</th>
<th>Hide</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="fruit in fruitnameDetail" ng-show="showall" ng-hide="hidef">
<td>{{fruit.fruitname}}</td>
<td><input type="checkbox" ng-model="hidef"></td>
<td>
<a class="btn btn-xs delete-record" ng-click="removefruitname($index)">
<i class="glyphicon glyphicon-trash"></i>
</a>
</td>
</tr>
</tbody>
</table>
<div><input type="checkbox" ng-model="showall"><span>SHOW ALL</span></div>
</body>
<script>
var app = angular.module("myApp", []);
app.controller('myController', function ($scope, $window) {
$scope.fruitnameDetail = [
{
"fruitname": "Banana"
},
{
"fruitname": "Mango"
},
{
"fruitname": "Orange"
}
];
$scope.addnew = function () {
var fruitnameDetail = {
fruitname: $scope.mdfruitname
};
$scope.fruitnameDetail.push(fruitnameDetail);
$scope.mdfruitname = '';
};
$scope.removefruitname = function (index) {
var name = $scope.fruitnameDetail[index].fruitname;
if ($window.confirm("Do you want to delete " + name + " ?")) {
$scope.fruitnameDetail.splice(index, 1);
}
};
});
</script>
Do not use ng-show and ng-hide at the same time. Just change a little bit your condition for ng-repeat. Here the example that should work:
<body ng-app="myApp" ng-controller="myController">
<h1>Fruits in Vietnam</h1>
<hr>
<form name="myForm">
<div class="input-group input-group-lg">
<input type="text" class="form-control" name="mdfruitname" id="txtfruitname" ng-model="mdfruitname"
required>
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button" ng-click="addnew()"
ng-disabled="myForm.mdfruitname.$pristine || myForm.mdfruitname.$invalid">Add
</button>
</div>
</div>
</form>
</div>
<table class="table table-striped">
<thead>
<tr>
<th>Description</th>
<th>Hide</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="fruit in fruitnameDetail" ng-show="showall || !hidef">
<td>{{fruit.fruitname}}</td>
<td><input type="checkbox" ng-model="hidef"></td>
<td>
<a class="btn btn-xs delete-record" ng-click="removefruitname($index)">
<i class="glyphicon glyphicon-trash"></i>
</a>
</td>
</tr>
</tbody>
</table>
<div><input type="checkbox" ng-model="showall"><span>SHOW ALL</span></div>
</body>

Echo output table data with paging from mysql through ajax into div modal bootstrap [ solved ]

now im creating a small quiz web app connecting to mysql db, everything goes well..
till have a problem to deal with create table inside modal pop up..
when i put the whole table inside div class="modal-body", its show on main page ( behind the modal ) not inside the modal.
since the problem that i faced above, im using diffrent approach to create a table, after doing reasearc on entire web forum, there is another way to create table without table tag, its said we can use div to create the table. it does and work well. the table show up inside modal with some data from database.
now it seem ive seen heaven door a head , but the pagination have block me up, i tried some code but its still no luck, since i go with div table i cant use instant table like datatable because its lack of node ( Non-table node initiation ) neither with traditional way url path.
all ineed is show one question per page with naviigate links ( prev | next )
Any assistance you can provide would be greatly appreciated
Below is the screenshoot the apps after user log in then it allow the user to choose which quiz they ready for
and this one how its look after user choosed the quiz provide
as we can see at the picture above , how can i colaborate with paging that can deal with div table ?
below is some code from quiz.php
<div class="table-container clearfix">
<table id="tableInvoicesList" class="table table-list hidden">
<thead>
<tr>
<th>Upload Modul</th>
<th>Modul</th>
<th>Peserta</th>
<th>Dibuat</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php
$sql = $koneksi->query("select * from quiz_list where to_list='$_SESSION[tipe]' order by id_list desc");
while($data=$sql->fetch_assoc()){
?>
<tr>
<td><?php echo date("d-m-Y",strtotime($data['cr_list'])); ?></td>
<td><?php echo $data['nm_list']; ?></td>
<td><?php echo $data['to_list']; ?></td>
<td><?php echo $data['by_list']; ?></td>
<td>
<!--
Mulai Quiz
-->
<!-- Button trigger modal -->
<a data-toggle="modal" data-id="<?php echo $data['kd_list'];?>" class="passingID">
<button type="button"
class="btn btn-primary btn-sm"
data-toggle="modal"
data-target="#showquiz<?php echo $data['kd_list'];?>">
<i class="fas fa-pencil-alt"></i> Quiz
</button>
</a>
</td>
</tr>
<!-- Modal -->
<div class="modal fade"
id="showquiz<?php echo $data['kd_list'];?>"
data-keyboard="false"
data-backdrop="static"
tabindex="-1"
role="dialog"
aria-labelledby="exampleModalCenterTitle"
aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle"><?php echo $data['nm_list']; ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<!--
<input type="text" class="form-control" name="idkl" id="idkl" value="">
-->
<style type="text/css">
.divTable
{
display: table;
width:auto;
background-color:#eee;
border:1px solid #666666;
border-spacing:5px;/*cellspacing:poor IE support for this*/
/* border-collapse:separate;*/
}
.divRow
{
display:table-row;
width:auto;
}
.divCell
{
float:left;/*fix for buggy browsers*/
display: table-cell;
width:555px;
background-color:#ccc;
}
</style>
<?php
$batas = 1;
$halaman = #$_GET['halaman'];
if(empty($halaman)){
$posisi = 0;
$halaman = 1;
}
else{
$posisi = ($halaman-1) * $batas;
}
$no = $posisi+1;
$result = $koneksi->query("select * from bank_soal where kd_list= '$data[kd_list]';");
while($tampil = $result->fetch_assoc()){
?>
<div class="divTable" id="page<?php echo $no; ?>">
<div class="headRow">
<div class="divCell"><?php echo $tampil['soal']; ?></div>
</div>
<div class="divRow">
<div class="divCell">001</div>
</div>
<div class="divRow">
<div class="divCell">xxx</div>
</div>
<div class="divRow">
<div class="divCell">ttt</div>
</div>
<div class="divRow">
<div class="divCell">ttt</div>
</div>
</div>
<?php $no++; } ?>
<hr>
<?php
$query2 = $koneksi->query("select * from bank_soal where kd_list='$data[kd_list]';");
$jmldata = mysqli_num_rows($query2);
$jmlhalaman = ceil($jmldata/$batas);
?>
<div class="text-center">
<ul class="pagination">
<?php
for($i=1;$i<=$jmlhalaman;$i++) {
if ($i != $halaman) {
echo "<li class='page-item'><a class='page-link' href='index.php?halaman=$i'>$i</a></li>";
} else {
echo "<li class='page-item active'><a class='page-link' href='#'>$i</a></li>";
}
}
?>
</ul>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
<script>
function showPages(id){
var totalNumberOfPages = 1;
for(var i=1; i<=totalNumberOfPages; i++){
if (document.getElementById('page'+i)) {
document.getElementById('page'+i).style.display='none';
}
}
if (document.getElementById('page'+id)) {
document.getElementById('page'+id).style.display='block';
}
};
</script>
<script>
$(document).on("click", ".passingID", function () {
var ids = $(this).attr('data-id');
$(".modal-body #idkl").val( ids );
});
</script>
<?php } ?>
</tbody>
</table>
<div class="text-center" id="tableLoading">
<p><i class="fas fa-spinner fa-spin"></i> Sedang memuat...</p>
</div>
after tried some other way,i found the solution for viewing data table inside modal problem,
so back to first plan, im keep using table tag to create the table, but not inside the modal body.
i create another file for ajax function to pass data from database and presenting the result within table and send it to div with id selector, for future reference , let me to share this piece of ajax code
main_modal.php
<!-- Modal -->
<div id="dataModal" class="modal fade" data-keyboard="false" data-backdrop="static"> <!--id dataModal wajib -->
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><?php echo $data['nm_list'];?></h5>
<button type="button" class="close" data-dismiss="modal"> ×</button>
</div>
<div class="modal-body" id="quiz_detail">
<!--Awal Modal Body-->
<!--Akhir Modal Body-->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function () {
$('.view_quiz').click(function(){
var quiz_id = $(this).attr("id");
$.ajax({
url:"page/quiz/view_quiz.php",
method:"post",
data:{quiz_id:quiz_id},
success:function(data){
$('#quiz_detail').html(data);
$('#dataModal').modal("show");
}
});
});
});
</script>
and for the paging , im using bootstrap datatable
<?php
if(isset($_POST["quiz_id"]))
{
$output = '';
$connect = new mysqli("localhost","root","","k3177986_admintugumulyo");
$query ="select * from bank_soal where kd_list= '".$_POST["quiz_id"]."'";
$result = $connect->query($query);
$jumlah = mysqli_num_rows($result);
$no = 0;
$output .='
<div class ="table-responsive col-md-12">
<table id="example" class="table table-bordered">
<thead>
<tr>
<th bgcolor="navy"><font size="2" face="verdana" color="white">SOAL</font></th>
</tr>
</thead>
<tbody>';
while($row = $result->fetch_assoc())
{
$no++;
$output .='
<form id="exampleForm" name="example" role="form">
<input type="hidden" name="id[]" value="'.$row["id_soal"].'">
<input type="hidden" name="jumlah" value="'.$jumlah.'">
<tr>
<td bgcolor="goldenrod">
<p><b>
'.$row["soal"].'
</b></p>
<p>
<input type="radio" id="" name="pilihan['.$row["id_soal"].']" value="a">
<label for="">'.$row["a"].'</label><br/>
</p>
<p>
<input type="radio" id="" name="pilihan['.$row["id_soal"].']" value="b">
<label for="">'.$row["b"].'</label><br/>
</p>
<p>
<input type="radio" id="" name="pilihan['.$row["id_soal"].']" value="c">
<label for="">'.$row["c"].'</label><br/>
</p>
<p>
<input type="radio" id="" name="pilihan['.$row["id_soal"].']" value="d">
<label for="">'.$row["d"].'</label><br/>
</p>
<input type="hidden" id="" name="jawaban['.$row["id_soal"].']" value="'.$row["x"].'">
</td>
</tr>
</form>
';
}
$output .='</tbody></thead></table></div>';
$output .='
<script>
$(document).ready(function() {
$("#example").DataTable({
"bInfo":false,
"lengthChange": false,
searching: false,
"targets": "no-sort",
"bSort": false,
"order": [],
"pageLength": 1
});
} );
</script>
';
echo $output;
}
?>

Codeigniter MySQL update

I have MySQL database used with Codigniter including following table too.
+-------------------+-----------------+------+-------+--------+
| update_request_id | update_stock_id | item | r_qty | status |
+-------------------+-----------------+------+-------+--------+
And used the following for loop in Controller, to update records in the table.
$count = count($this->input->post('item_id'));
$items = $this->input->post('item_id');
$qts = $this->input->post('qty');
for ($x = 0; $x < $count; $x++) {
$udetails[$x]['update_stock_id'] = $id;
$udetails[$x]['item'] = $items[$x];
$udetails[$x]['r_qty'] = $qts[$x];
$udetails[$x]['status'] = 1;
}
And the following View used to get relevant values for the controller.
<?php
if(!empty($itemReqFromHD)){
$newMaster=$itemReqFromHD[0];
}
?>
<script type="text/javascript">
$(document).on("change", "#item", function () {
$.ajax({
'url': '<?=site_url("item/isExistProduct/?q=")?>' + $('#item').val(),
'method': 'GET',
'success': function (data) {
//console.log(data);
var jData = JSON.parse(data);
if (jData.status == true) {
$('#request_table').append('<tr>' +
'<td ><span id="product" >' + jData.data[0].item_name + '</span>' +
'<input type="hidden" id="item_id[]" name="item_id[]" value="'+jData.data[0].item_id+'">' +
'</td>' +
'<td class="text-center"><input class="form-control" autofocus required type="number" step="any" id="qty['+jData.data[0].item_id+']" name="qty['+jData.data[0].item_id+']" ></td>' +
'<td class="text-center" ><i class="fa fa-remove remove" style="cursor: pointer"></i></td>' +
'</tr>');
}
},
'error': function () {
}
});
});
$(document).on("click", ".remove", function () {
$(this).closest('tr').remove();
});
</script>
<div class="box box-info">
<div class="box box-info collapsed-box">
<div class="box-header with-border">
<h3 class="box-title">Update Item Request From HD</h3>
<div class="box-tools pull-right">
<button type="button" class="btn btn-box-tool" style="font-size: 16px;" data-widget="collapse"><i
class="fa fa-plus"></i>
</button>
</div>
<!-- /.box-tools -->
</div>
<!-- /.box-header -->
<div class="box-body" style="display: block">
<form action="<?= site_url('item/editItemReqFromHD/'.$newMaster->update_stock_id) ?>" method="post">
<div class="row">
<div class="col-md-3">
<div class="form-group"><label>Request Date</label>
<input type="date" name="request_date" id="request_date" class="form-control" value="<?=$newMaster->billed_date?>">
</div>
</div>
<div class="col-md-6">
<div class="form-group"><label>Select Product</label>
<select name="item" id="item" class="form-control select2" >
<option value="">Select Product</option>
<?php
if (!empty($products)) {
foreach ($products as $row) {
?>
<option value="<?= $row->item_id ?>"><?= $row->item_name ?></option>
<?php
}
}
?>
</select>
</div>
</div>
</div>
<!--table-->
<div class="col-md-12 column">
<div class="col-md-12">
<div class="control-group table-group">
<label class="table-label">Request Items *</label>
<div class="controls table-controls">
<table id="request_table"
class="table items table-striped table-bordered table-condensed table-hover">
<thead>
<tr style="background-color: #3c8dbc">
<th class="col-md-8">Product Name</th>
<th class="text-center" class="col-md-2">Quantity</th>
</th>
<th style="width: 30px !important; text-align: center;">
<i class="fa fa-trash-o" style="opacity:0.5; filter:alpha(opacity=50);"></i>
</th>
</tr>
</thead>
<tbody>
<?php
foreach ($itemReqFromHD as $row){
?>
<tr>
<td ><?=$row->item_name?>
<input type="hidden" id="item_id[]" name="item_id[]" value="<?=$row->item_id?>">
</td>
<td class="text-center"><input class="form-control" value="<?=$row->r_qty?>" required type="number" step="any" id="r_qty[<?=$row->item_id?>]" name="r_qty[<?=$row->item_id?>]" ></td>
<td class="text-center"><i class="fa fa-remove remove" style="cursor: pointer"></i></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-8"></div>
<div class="col-md-4">
<button type="submit" class="btn btn-primary btn-block">Update Request</button>
</div>
</div>
</form>
</div>
</div>
</div>
All codes are working fine but at the time of the update the column 'r_qty' is not edited, leaving the table as follows:
Array
(
[0] => Array
(
[update_stock_id] => 577
[item] => 2
[r_qty] =>
[status] => 1
)
[1] => Array
(
[update_stock_id] => 577
[item] => 4
[r_qty] =>
[status] => 1
)
)
I could not catch what I am going wrong ? Can anyone help me ?

splice(index,1) not removing element

I am writing a small program in Vue.js, but I am getting stuck with an error.
I want the X button to remove each item in a list. I used splice(index,1), but the item isn't being removed. What am I missing?
My HTML:
<div id="app" class="container">
<div class="row">
<div class="col-md-4">
<h1>Add Student</h1>
<div class="form-group">
<label for="name">Name</label>
<input type="text" id="name" v-model="newStudent.name" class = "form-control" placeholder="Student Name">
</div>
<div class="form-group">
<label for="address">Address</label>
<input type="text" id="address" v-model="newStudent.address" class = "form-control" placeholder="Address">
</div>
<button class="btn btn-success" v-on:click = "addStudent">Add</button>
</div>
<div class="col-md-8">
<h1>All Students</h1>
<table class="table table-striped">
<thead>
<tr>
<td>Name</td>
<td>Address</td>
<td>Action</td>
</tr>
</thead>
<tbody>
<tr v-for = "student in students">
<td>{{student.name}}</td>
<td>{{student.address}}</td>
<td><button type="button" class="btn btn-danger" v-on:click="deleteStudent($index)">X</button></td>
</tr>
</tbody>
</table>
</div>
</div> <!--End of Row-->
<br>
<br>
<div class="row">
<div class="col-md-12">
<pre>{{ $data | json }}</pre>
</div>
</div>
</div>
My JS:
<script>
new Vue({
el: "#app",
data: {
newStudent: {name: "", address: ""},
students: []
},
methods: {
addStudent: function(){
var name = this.newStudent.name.trim();
var address = this.newStudent.address.trim();
if(name && address){
this.students.push({name: name, address: address});
this.newStudent = {name: "", address: ""};
$("#name").focus();
}
},
deleteStudent: function(index){
this.students.splice(index,1)
}
}
});
</script>
The $index variable was removed in Vue 2. So, you're not passing the index in correctly.
Specify the index variable in the v-for and pass that to the deleteStudent method instead:
<tr v-for="student, index in students">
<td>{{student.name}}</td>
<td>{{student.address}}</td>
<td>
<button
type="button"
class="btn btn-danger"
v-on:click="deleteStudent(index)"
>X</button>
</td>
</tr>
This is covered in the documentation on list rendering in Vue.

Displaying data from database from Controller to View using jQuery AJAX request CodeIgniter without refreshing the page

How i can load particular portion of page in Codeigniter? The Ajax is working but it reloads all views by calling controller name(like header, body, footer) but i want only reload body, How can i separate the code to work properly.
Its Ajax code
$('label#showdata').click(function(){
var fromdate =document.getElementById('fromdate').value;
var todate = $(this).val();
var dataString = 'fromdate='+ fromdate+'todate='+todate;
$.ajax({
type: "POST",
url: "https://chotigaadi.com/myadmin/references",
data: dataString,
cache: false,
success: function(html)
{
$("div#result").html(html).show();
//alert(dataString);
}
});
});
Its my View
<div class="col s12 m12">
<form action="<?php echo base_url();?>myadmin/ExportCSV" method="POST">
<div class="col s12 m3">
<h5 class="center" style="color:green;font-weight:bold;">Registered Members List</h5>
</div>
<div class="col s12 m2">
<div class="input-field col s12">
<label for="date"> <i class="fa fa-calendar"></i> Select from date below:</label>
</br>
<input name="fromdate" id="fromdate" type="date" class="datepicker" required>
</div>
</div>
<div class="col s12 m3">
<div class="input-field col s12">
<label for="date"> <i class="fa fa-calendar"></i> Select to date below:</label>
</br>
<input name="todate" id="todate" type="date" class="datepicker" required>
</div>
</div>
<div class="col s12 m4">
<div class="col s6">
<label id="showdata" class="btn waves-effect waves-light orange right" value="Show">Show Results</label>
</div>
<div class="col s6">
<input type="submit" id="datesubmit" class="btn waves-effect waves-light green right" value="Export Data" />
</div>
</div>
</form>
<div id="result">
<table class="highlight">
<thead>
<tr style="background-color:#ccc;">
<th data-field="name">ID</th>
<th data-field="name">Referee</th>
<th data-field="rname">Reference</th>
<th data-field="email">Email</th>
<th data-field="phone">Phone</th>
</tr>
</thead>
<tbody>
<?php
foreach ($results as $row)
{?>
<tr style="">
<td>
<?php echo $row->firstname;?>
</td>
<td>
<?php echo $row->name; ?>
</td>
<td>
<?php echo $row->email; ?>
</td>
<td>
<?php echo $row->phone; ?>
</td>
</tr>
<?php }?>
</tbody>
</table>
</div>
</div>
My Controller Code:
function references(){
if (!$this->check_user()) {
redirect('myadmin/login/');
}
else
{
if(isset($_POST['fromdate']) && isset($_POST['todate']))
{
$fromdate=new DateTime(str_replace("-","",$_POST['fromdate']));
$fromdate=$fromdate->format('Y-m-d H:i:s');
$todate=new DateTime(str_replace("-","",$_POST['todate']));
$todate=$todate->format('Y-m-d H:i:s');
}
else
{
$fromdate=new DateTime('2015-12-10 14:28:27');
$fromdate=$fromdate->format('Y-m-d H:i:s');
$todate=new DateTime(date("Y-m-d"));
$todate=$todate->format('Y-m-d H:i:s');
}
$config = array();
$config["base_url"] = base_url() . "myadmin/references";
$config["total_rows"] = $this->myadmin_model->record_count($fromdate, $todate);
$config["per_page"] = 8;
$config["uri_segment"] = 3;
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["results"] = $this->myadmin_model->fetch_userdata($config["per_page"], $page, $fromdate, $todate);
$data["links"] = $this->pagination->create_links();
$this->load->view('/admin/myadminheader');
$this->load->view('/admin/myadmin',$data);
$this->load->view('/admin/myadminfooter');
}
}
I want to reload only view as $this->load->view('/admin/myadmin',$data); by ajax How I can do this?
If you just want to change your middle part only than do not load header and footer in ajax calling function.
Remove these two lines:
$this->load->view('/admin/myadminheader');
$this->load->view('/admin/myadminfooter');
It just only:
$this->load->view('/admin/myadmin',$data);
This will only return the middle part not header footer in ajax response.
Side note:
If you are using this function directly from some where than you need to pass any param from ajax request for checking either request from ajax or not.
Don't load the view in controller function. Just print the result in controller function and write a die() function after that. Clear the result div in JavaScript function before load the html.