datatable is not working properly with my ajax code - json

I had a Crud, in which I obtained the data of each record to be able to edit them, through a button("Asignar") with an event. In order to add a search bar I wanted to implement the DataTable plugin, but this, when importing my button, causes a conflict with the code; I would like to know what I must modify so that the button is operative with the DataTatable plugin.
DataTable Controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Siniestro;
class DataTableController extends Controller
{
public function paraderivar(Request $request)
{
$siniestros = Siniestro::select('id', 'siniestro','fechaip', 'modalidad','direccion','localidad', 'inspector')->get();
return datatables()->of($siniestros)
->addColumn('edit', '<button class="btn btn-info btn-sm" onclick="editData(value.id)"> Asignar </button>')
->rawColumns(['edit'])
->toJson();
}
}
blade.view
#extends('layouts.app')
#section('content')
<section class="section">
<div class="section-header">
<h3 class="page__heading">Derivar IP</h3>
</div>
<div class="section-body">
<div class="row">
<div class="col-sm-9">
<div class="card">
<div class="card-header">
<h4>Siniestros para derivar</h4>
</div>
<div class="card-body">
<table class="table table-sm m-1 p-1 table-bordered table-hover table-striped tablita" style="width:100%">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Siniestro</th>
<th scope="col">Fecha IP</th>
<th scope="col">Modalidad</th>
<th scope="col">Dirección</th>
<th scope="col">Localidad</th>
<th scope="col">Inspector</th>
<th scope="col">Acciones</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-sm-3" style="position:fixed; bottom:250px; right:0px">
<div class="card">
<div class="card-header">
<span id="addT">Asignar IP</span>
<span id="updateT">Asignar IP</span>
</div>
<div class="card-body">
<div class="col-xs-4 col-sm-4 col-md-4">
<div class="form-group">
<label for="siniestro">Siniestro</label>
<input type="text" name="siniestro" id="siniestro" class="form-control">
</div>
</div>
<div class="col-xs-4 col-sm-4 col-md-4">
<label for="inspector">inspector</label>
<select class="form-select col-xs-12 col-sm-12 col-md-12" aria-label="Default select example" id="inspector"´for="inspector" name="inspector"">
#foreach ($users as $user)
<option value="{{ $user->id }}">{{ $user->name }}</option>
#endforeach
</select>
</div>
<div class="col-xs-4 col-sm-4 col-md-4">
<div class="form-group">
<label for="patente">Patente</label>
<input type="text" name="patente" id="patente" class="form-control">
</div>
</div>
<div class="col-xs-4 col-sm-4 col-md-4">
<div class="form-group">
<label for="fechaip">Fecha IP</label>
<input type="date" name="fechaip" id="fechaip" class="form-control">
</div>
</div>
<input type="hidden" id="id">
<!-- <button type="button" href="#" data-target="#ModalEnviar" class="btn btn-primary m-2" data-toggle="modal">Enviar IP</button> -->
<button type="submit" id="updateButton" class="btn btn-primary btn-sm" onclick="enviarData(event)">Notificar</button>
<button type="submit" id="updateButton" class="btn btn-primary btn-sm" onclick="updateData(event)">Update</button>
</div>
</div>
</div>
</div>
</div>
</section>
#endsection
#section('javas')
<script>
$('.tablita').DataTable({
"processing": "true",
"serverSide": "true",
"ajax": "{{route('datatable.paraderivar')}}",
"select": "true",
"columns":[
{data: 'id'},
{data: 'siniestro'},
{data: 'fechaip'},
{data: 'modalidad'},
{data: 'direccion'},
{data: 'localidad'},
{data: 'inspector'},
{data: 'edit'},
]
});
</script>
<script>
$('#addT').hide();
$('#addButton').hide();
$('#updateT').show();
$('#updateButton').show();
$.ajaxSetup({
headers:{
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
})
//---------------------------------------------- Llamar datos de la BD ---------------------------------------------------------------
function allData(){
$.ajax({
type: "GET",
dataType: "json",
url: "/teacher/all",
success: function (response){
var data = ""
$.each(response, function(key, value){
data = data + "<tr>"
data = data + "<td>"+value.id+"</td>"
data = data + "<td>"+value.siniestro+"</td>"
data = data + "<td>"+value.fechaip+"</td>"
data = data + "<td>"+value.modalidad+"</td>"
data = data + "<td>"+value.direccion+"</td>"
data = data + "<td>"+value.localidad+"</td>"
data = data + "<td>"+value.inspector+"</td>"
data = data + "<td>"
data = data + "<button class='btn btn-info btn-sm' onclick='editData("+value.id+")'>Asignar</button>"
data = data + "</td>"
data = data + "</tr>"
})
$('tbody').html(data);
}
})
}
// --------------------------------------------- fin de llamar datos de la DB ----------------------------------------------------------
allData();
// --------------------------------------------- Limpiar los campos despues del submit -------------------------------------------------
function clearData(){
$('#siniestro').val('');
$('#fechaip').val('');
$('#inspector').val('');
$('#nameError').text('');
$('#titleError').text('');
$('#instituteError').text('');
}
// --------------------------------------------- fin de limpiar los campos despues del submit -------------------------------------------------
// --------------------------------------------- Agregar registros a la table de BD -------------------------------------------------
function addData(){
var siniestro = $('#siniestro').val();
var fechaip = $('#fechaip').val();
var inspector = $('#inspector').val();
var patente = $('#patente').val();
$.ajax({
type: "POST",
dataType: "Json",
data: {siniestro:siniestro, fechaip:fechaip, inspector:inspector, patente:patente},
url:"/teacher/store/",
success: function(data){
allData();
clearData();
console.log('datos agregados con éxito');
},
error: function(error){
$('#nameError').text(error.responseJSON.errors.name);
$('#titleError').text(error.responseJSON.errors.title);
$('#instituteError').text(error.responseJSON.errors.institute);
}
})
}
// --------------------------------------------- fin de agregar registros a la table de BD -------------------------------------------------
// --------------------------------------------- Editar registros a la table de BD ---------------------------------------------------------
function editData(id){
$.ajax({
type:"get",
dataType:"json",
url:"/teacher/edit/"+id,
success: function(data){
$('#addT').hide();
$('#addButton').hide();
$('#updateT').show();
$('#updateButton').show();
$('#id').val(data.id);
$('#siniestro').val(data.siniestro);
$('#fechaip').val(data.fechaip);
$('#inspector').val(data.inspector);
$('#patente').val(data.patente);
console.log(data);
}
})
}
// --------------------------------------------- Fin de editar registros a la table de BD -------------------------------------------------
// --------------------------------------------- Update de registros a la table de BD -----------------------------------------------------
function updateData(event){
event.preventDefault();
var id = $('#id').val();
var siniestro = $('#siniestro').val();
var fechaip = $('#fechaip').val();
var inspector = $('#inspector').val();
var patente = $('#patente').val();
$.ajaxSetup({
headers:{
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
})
$.ajax({
type: "PUT",
dataType: "json",
data: {inspector:inspector, siniestro:siniestro, fechaip:fechaip, patente:patente},
url: "/teacher/update/"+id,
success: function(response){
allData();
clearData();
console.log('Siniestro asignado con éxito');
}
})
}
</script>
#endsection
When the page is reloaded, it seems that the DataTable plugin does not load correctly, since it does not page by 10, but loads all the records and the table becomes large... although I can click on the "assign" button and retrieve the attributes of each record. But, when I search for something in the search bar, the plugin pages 10 records, and when I click on each "Assign" button, it no longer sends me the data, but instead gives me the error "Failed to load resource: the server responded with a status of 404 (Not Found)." When I look at the error detail, it tells me the following: "{message: "No query results for model [App\Models\Siniestro] undefined",…}"

Related

Angularjs use one controler in two views, scope is not loading

I have an e-commerce page. I want when the user deletes a product from the shopping cart to reload the specific divs. I have the index page that contains
a div with an ng-repeat with my products, and in the index I have an content view with the same ng-repeat. I want when for example I delete a
product, to update the these ng-repeat. I tried, the $rootscope.$digest; and $scope.$apply(); but there are not working. Below, you can see my code.
My index page
<div ng-controller="ShoppingCartCtrl">
<div data-toggle="dropdown"> </div>
<ul>
<li ng-repeat="item in resultShoppingCart">
<a title="Product Title Here" ui-sref="single_product({id:item.productId})"></a>
<div class="product-details">
<div class="access"><a title="Remove This Item" ng-click="delete(userId,item.productId)">Remove</a> <a class="btn-edit" title="Edit item" ui-sref="shoppingCart"><i class="icon-pencil"></i><span class="hidden">Edit item</span></a> </div>
<p class="product-name"><a ui-sref="single_product({id:item.productId})" ng-bind="item.productName"></a> </p>
<strong ng-bind="item.quantity"></strong> x <span class="price" ng-bind="item.unitPrice"></span>
</div>
</div>
</li>
</ul>
</div>
</div>
<div class="actions">
<a ui-sref="shoppingCart"><span>View Cart</span></a>
</div>
<div id="wrap">
<!-- Content -->
<div class="container">
<div ui-view=""></div>
</div>
</div>
My shopping cart page
<tbody>
<tr ng-repeat="item in resultShoppingCart track by $index">
<td class="cart_product"><a ui-sref="single_product({id:item.productId})"></a></td>
<td class="cart_description">
<p class="product-name" ng-bind="item.productName"></p>
</td>
<td class="price" ng-bind="item.unitPrice"><span></span></td>
<td class="qty">
<input class="form-control input-sm" type="text" ng-value="item.quantity" ng-model="item.quantity">
<i class="fa fa-plus" ng-click="changeQuantity(item, 1)"></i> <i class="fa fa-minus" ng-click="changeQuantity(item, -1)"></i>
</td>
<td class="price" ng-bind="item.price"><span></span></td>
<td class="action"><a ng-click="delete(userId,item.productId)">Delete item</a></td>
</tr>
</tbody>
And my shopping cart controller:
$scope.delete = function (userId, productId) {
var jsonDelete = '...';
dataProvider.delete(jsonDelete).then(function (response) {
//$scope.$digest(); //not working
//$scope.$apply();//not working
});
$state.reload();
//$scope.$digest;//not working
//$scope.$apply();//not working
};
With the state.reload I can reload my shopping cart page. Can anyone help me?
Few modifications will make it work.
Pass $index to your delete function, like,
ng-click="delete(userId,item.productId, $index)"
Then inside your delete handler, you can use splice to delete the object from your existing array. Like
$scope.delete = function (userId, productId, index) {
var jsonDelete = '...';
dataProvider.delete(jsonDelete).then(function (response) {
$scope.resultShoppingCart.splice(index, 1);
});
$state.reload();
};
Edit:
Use events to update the parent value. Like,
In shopping cart
$scope.delete = function (userId, productId, index) {
var jsonDelete = '...';
dataProvider.delete(jsonDelete).then(function (response) {
$scope.resultShoppingCart.splice(index, 1);
$rootScope.$emit('updateList',productId);//Passing productid instead of index is safer as it is not necessary to stick to the order of array.
});
$state.reload();
};
In index page
Catch the event which is triggered after deleting.
$rootScope.$on('updateList', function (productId) {
for (let i = 0; i < $scope.resultShoppingCart.length ; i++) {
if ($scope.resultShoppingCart[i].productId == productId) {
$scope.resultShoppingCart.splice(i, 1);
break;
}
}
});

codeigniter form submission using ajax and display return data in table

I submitting one form in view page and I want to, when I click on submit button the form data need to be saved in a database table and that data need to be shown in the table without refresh page.
Here is my view code:
<div class="col-md-12">
<div class="row">
<div>
<table class="table table-striped table-hover table-responsive">
<thead>
<tr class="">
<th>Director</th>
<th>Partner</th>
<th>Duration</th>
<th>Comments</th>
</tr>
</thead>
<tbody id="hodm_results">
</tbody>
</table>
</div>
</div>
</div>
<?php
$attributes = array('class' => 'form-horizontal','id'=>'hodm_comments');
echo form_open('', $attributes);
?>
<div class="row">
<div class="col-md-12">
<div class="col-sm-3">
<div class="input-group">
<span>Director</span>
<?php echo form_input(['class'=>'form-control autofocus','id'=>'director','name'=>'director','value'=>set_value('director',$wip->director)]); ?>
</div>
</div>
<div class="col-sm-3">
<div class="input-group">
<span>Partner</span>
<?php echo form_input(['class'=>'form-control autofocus','id'=>'partner','name'=>'partner','value'=>set_value('partner',$wip->partner)]); ?>
</div>
</div>
<div class="col-sm-3">
<div class="input-group">
<span>Duration</span>
<?php echo form_input(['class'=>'form-control autofocus','id'=>'duration','name'=>'duration']); ?>
</div>
</div>
<div class="col-sm-3">
<div class="input-group">
<span>Comments</span>
<?php echo form_textarea(['class'=>'form-control autofocus','id'=>'comments','name'=>'comments','rows'=>'3']); ?>
<input type="hidden" name="id_hidden" value="<?php echo $wip->id; ?>">
</div>
</div>
</div>
</div>
<input class="btn btn-primary" type="submit" name="submit" value="submit">
<?php
echo form_close();
?>
</section>
<!--main content end-->
</section>
Here is my JQuery code:
<script type='text/javascript' language='javascript'>
$('#hodm_comments').submit(function (event) {
$.ajax({
url:"<?php echo base_url();?>digital/dashboard/insert_hodm_comments",
type: 'POST',
dataType: 'JSON',
success:function (data) {
$('#hodm_results').html(data);
}
});
event.preventDefault();
});
</script>
Here is my controller code:
public function insert_hodm_comments(){
/* Checking the all validation of Hodm Comment form form*/
$this->form_validation->set_rules('director', 'Name of Director', 'required');
$this->form_validation->set_rules('partner', 'Partner', 'required');
$this->form_validation->set_rules('duration', 'No Of Hours', 'required');
$this->form_validation->set_rules('comments', 'Comments of the task', 'required');
if ($this->form_validation->run()) {
/* Taking the data from form*/
$partner = $this->input->post('partner');
$director = $this->input->post('director');
$duration = $this->input->post('duration');
$comments = $this->input->post('comments');
$id = $this->input->post('id_hidden');
$data = array(
'partner' =>$partner,
'director' =>$director,
'duration' =>$duration,
'comments' =>$comments,
'hodm_id' =>$id
);
$add=$this->pojo->add_hodm_comments($data);
/* Display Success message if data inserted successfully in database*/
if($add){
$result_html = '';
$result_set = $this->pojo->get_hodm_comments();
foreach($result_set as $result) {
$result_html .= '
<tr>
<td>' . $result->director . '</td>
<td>' . $result->partner . '</td>
<td>' . $result->duratrion . '</td>
<td>' . $result->comments . '</td>
</tr>';
}
echo json_encode($result_html);
//$this->session->set_flashdata('hodm_form',"All HODM Data Inserted Successfully.");
//$this->session->set_flashdata('hodm_form_class','alert-success');
}else{
/* Displaying the error message*/
$this->session->set_flashdata('hodm_form',"failed to add, Please Try again");
$this->session->set_flashdata('hodm_form_class','alert-danger');
}
return redirect('digital/dashboard/wip_hodm_comments_section');
} else {
$this->load->view('digital/hodm/dashboard_hodm_work/wip_hodm_comments');
}
}
Here is Model:
public function add_hodm_comments($data){
$this->db->insert('hodm_wip_comments', $data);
return TRUE;
}
public function get_hodm_comments(){
$this->db->select('*');
$this->db->from('hodm_wip_comments');
$query=$this->db->get();
return $result=$query->result();
}
Please help me to find the solution I stuck in this code.
Thank you
Just change your ajax part to below
<script type='text/javascript' language='javascript'>
$('#hodm_comments').submit(function (event) {
$.ajax({
url:"<?php echo base_url();?>digital/dashboard/insert_hodm_comments",
type: 'POST',
data : $('#hodm_comments').serialize(),
success:function (data) {
$('#hodm_results').html(data);
}
});
event.preventDefault();
});
</script>
and in your controller change this echo json_encode($result_html); to echo $result_html;
this works perfect in my side with your code :)
What you can do simply is to echo response from within your controller function, get the return data of ajax call and add it into a div or as tr in to an existing table.

e-form add row presents at top of table

I have an angularjs application and am using e-form to view/add/edit rows in a table. When I choose add, I would like the new row to present at the top of the list rather than the bottom of the list. Once the row is added, it should sort according to the sort order I have designed. But for usability, it's friendlier for the user if the new row is at the top of the page. Any ideas, suggestions, etc. greatly appreciated.
HTML:
<md-button type="button" class="md-accent md-raised" ng-click="searchText=undefined; addContributor()">+ Add Contributor</md-button>
</div>
</md-card-header-text><label>Search: <input ng-model="searchText"></label><button-xs ng-click="searchText=undefined">Clear</button-xs>
</md-card-header>
<md-card-content class="px-helper-pt-0">
<md-table-container>
<table md-table md-progress="vm.contributors">
<colgroup><col></colgroup>
<colgroup><col></colgroup>
<colgroup><col></colgroup>
<colgroup><col></colgroup>
<thead md-head md-order="vm.query.order">
<tr md-row>
<th ng-show=false md-column md-order-by="id" class="md-body-2"><span class="md-body-2">Id</span></th>
<th md-column md-order-by="name" class="md-body-2"><span class="md-body-2">Name</span></th>
<th md-column md-order-by="role" class="md-body-2"><span class="md-body-2">Role</span></th>
<th md-column class="md-body-2"><span class="md-body-2">Edit</span></th>
<th md-column class="md-body-2"><span class="md-body-2"></span></th>
</tr>
</thead>
<tr dir-paginate="item in vm.contributors | filter:{searchField:searchText} | itemsPerPage: 25 | orderBy: vm.query.order">
<td ng-show=false md-cell><span editable-text="item.id" e-disabled e-name="id" e-form="rowform">{{item.id}}</span></a></td>
<td md-cell><span editable-text="item.name" e-name="name" e-form="rowform">{{item.name}}</span></a></td>
<td md-cell><span editable-text="item.role" e-name="role" e-form="rowform">{{item.role}}</span></a></td>
<td style="white-space: nowrap">
<form editable-form name="rowform" onbeforesave="saveContributor($data, item.id)" ng-show="rowform.$visible" class="form-buttons form-inline" shown="inserted == item">
<md-button type="submit" ng-disabled="rowform.$waiting" class="md-accent md-raised">save</md-button>
<md-button type="button" ng-disabled="rowform.$waiting" ng-click="rowform.$cancel()" class="btn btn-default">Cancel</md-button>
</form>
<div class="buttons" ng-show="!rowform.$visible">
<md-button type="button" class="md-primary md-raised" ng-click="rowform.$show()">edit</md-button>
<md-button class="md-warn md-raised" ng-confirm-message="Are you sure you want to delete?" ng-confirm-click="deleteContributor(item.id)">Delete</md-button>
</div>
</td>
</tr>
</table>
</md-table-container>
controller:
activate();
function activate() {
vm.promises = [getContributors()];
return $q.all(vm.promises).then(function() {
logger.info('Activation', 'Contributors Controller', 'Template Rendered');
});
}
vm.query = {
order: 'name'
};
$scope.deleteContributor = function(contributorId) {
contributorsFactory.deleteContributor(contributorId).then(function(status) {
console.log(status);
if (status !== 409) {
$mdToast.show($mdToast.simple().textContent('Deleted Contributor' + contributorId).theme('success').position('left top'));
contributorsFactory.deleteItemFromArrayById(contributorId, vm.contributors);
}
window.setTimeout(function() {window.location.reload();}, 1000);
});
};
$scope.saveContributor = function(data, id) {
contributorsFactory.updateContributor(JSON.stringify(data), id).then(function(res) {console.log(res);});
$mdToast.show($mdToast.simple().textContent('Form Saved').theme('success').position('left top'));
window.setTimeout(function() {window.location.reload();}, 1000);
};
$scope.addContributor = function() {
$scope.inserted = {
value: ''
};
vm.contributors.push($scope.inserted);
};
function getContributors() {
var item;
return dojo.contribCollection()
.then(function(data) {
vm.contributors = data;
angular.forEach(vm.contributors, function(e) {
e.searchField = e.id + ' ' + e.name + ' ' + e.role + ' ';
If you want new item display in the first . You can try use splice
vm.contributors.splice(0,0,itemyouwanpush)
And why you mixing $scope with controllerAs? Just use one . In html you change ng-click to
vm.addContributor()
And in controller
vm.addContributor()=function(){
vm.contributors.splice(0,0,itemyouwanpush)
}
And dont forget
var vm = this; in controller
This is the code that resolved the issue:
controller.js
vm.contributors.splice(0, 0, $scope.inserted = {name: '', role: ''});

Modal with controller in Laravel

Hey friends I am creating a simple modal to show me the data of a provider and honestly is costing me quite a lot; Can someone give me a hand?
modal:
<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
aria-labelledby="myModal">
<div class="modal-dialog"
role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModal">Detalle del Proveedor: </h4>
</div>
<div class="modal-body">
<div class="table-responsive">
<table class="table table-stripped table-bordered table-hover" id="table-detalle-proveedores">
<thead>
<tr>
<th>Nombre</th>
<th>Apellido</th>
<th>Telefono</th>
<th>Email</th>
<th>Dirección</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
</div>
</div>
</div>
</div>
botton of modal
<a href="" class="btn btn-primary btn-detalle-proveedores" data-id="{{ $proveedores->id }}"
data-path="{{ route('admin.proveedores.item') }}" data-toggle="modal"
data-target="#myModal"
data-token="{{ csrf_token() }}">
<i class="fa fa-external-link"></i>
</a>
Route
Route::post('admin/proveedores/item', [
'as' => 'admin.proveedores.item',
'uses' => 'ProveedoresController#Item']);
function of controller
public function item(Request $request)
{
$items = Proveedores::select($request->id);
return json_encode($items);
}
I was testing that one and others but the maximum that I get it to show me in the console an empty object
Firstly, in your javascript you're passing the id as proveedores_id but in your controller you're trying to access it with $request->id.
It might be an idea to have a look at https://laracasts.com/series/laravel-from-scratch-2017/episodes/8
Secondly, with using just select you're just going to be returning a json encoded version of Builder.
To get your request to actually return an instance of Proveedores you would do something like:
public function item(Request $request)
{
$item = Proveedores::findOrFail($request->id);
return compact('item');
}
This also means you can remove the for loop inside your success method and simply access the data with response.item.* e.g.
function (response) {
console.log(response)
table.html('')
var fila = "<tr>" +
"<td>" + response.item.name + "</td>" +
"<td>" + response.item.last_name + "</td>" +
"<td>" + response.item.tel + "</td>" +
"<td>" + response.item.address + "</td>" +
"</tr>";
table.append(fila);
}
Hope this helps!

Inserting data into database by WEB API in angular JS

I am new into angular JS and web api world. Recently facing difficulty in sending data into database through web api and angular. I am able to load json data from webapi.Any help will be highly appreciated.
My html:
<div class="container-fluid" ng-controller="SubmitDataCtrl">
<div class="container text-center" style="margin-bottom:5px">
<div id="divTables">
<table id="tbl_SMDetails" class="display responsive nowrap aleft" cellspacing="0" width="100%">
<thead>
<tr>
<th class="all">Name</th>
<th class="all">CTSID</th>
<th class="all">FDID</th>
<th class="all">Name of the Project</th>
<th class="all">Effort Hour</th>
<th class="all">Month</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="showData in loadData">
<td>{{showData.EmpName}}</td>
<td>{{showData.EmpCognizantID}}</td>
<td>{{showData.FDID}}</td>
<td><input id="Text1" type="text" />{{showData.projectName}}</td>
<td><input id="Text1" type="text" />{{showData.effortHour}}</td>
<!--<td>{{date | date:'MM-dd-yyyy}}</td>-->
<td>{{showData.date}}</td>
</tr>
</tbody>
</table>
</div>
</div>
<div>
<a ng-href='#SubmitData' class="btn btn-default" ng-click='go()'>Submit</a><span></span>
<a ng-href='#SubmitData' class="btn btn-default" ng-click=''>Reset</a>
</div>
</div>
My service page looks like:
var request = $http({
method: method_args,
url: myConfig.ServiceURL + url,
data: JSON.stringify(input_data),
Accept: 'application/json',
headers: {'Content-Type':'application/json'},
xhrFields: {
withCredentials: true
}
});
}
and my controller is
App.controller("SubmitDataCtrl", function($scope, ajaxService) {
//login user
ajaxService.MakeServiceCall("employee/GetTeamMember? superVisiorCogniID=256826", "GET", "")
.then(function effortData(data)
{
// alert(data);
$scope.date = new Date();
$scope.loadData = data;
showData = $scope.loadData;
for (var i = 0; i < showData.length; i++)
{
//alert(showData[i].EmpName + showData[i].EmpCognizantID + showData[i].FDID);
}});
$scope.go = function()
{
//alert('clicked');
ajaxService.MakeServiceCall("effort/SaveTeamEfforts?hourLoadDate=08/20/2015&hourLoadByCogniID=256826&forMonth=July", "POST", Employee).then(function save() {
var Employee =
{
"EmpCogniID": showData[i].EmpCognizantID,
"FDTimeCardHour": showData[i].effortHour,
"HourLoadDate": 08/11/2015,
"HourLoad`enter code here`By": "256826",`enter code here`
"ForMonth": "july"
}
}).success(function (Employee)
{
$scope.showData[i] = Employee;
});
alert(Employee); }});
It's hard to answer without knowing what the API POST call should do.
Can you confirm that the POST you are making to effort/saveTeamEfforts works by executing it using a REST tester in the browser?
if that is working, you should add an .error function to your API call and see what error is returned as dan has sugested above
L