It shows 500 internal server error when retrieving data through ajax. But the whole code works well in my localhost. And i am facing this error for the first time, so i am not sure whether this error is caused due to fetching data through AJAX. If it is not the correct reason please get me the correct reason.
this is my coding
$.ajax({
type:"POST",
url:"api_fle/get_post",
data:{u_id:u_id,type:'all13'},
success:function(response){
if(response!=0){
var parsed = $.parseJSON(response);
date = new Array();
events = new Array();
$.each(parsed,function(i,parsed){
if(parsed.shred.length>15){var shred=jQuery.trim(parsed.shred).substring(0, 14) + '...';} else{var shred=parsed.shred;}
if(parsed.cmpny_name == parsed.shred){var sharedd=parsed.cmpny_name; var sha=""; var pic=parsed.pro_pic;}else{var sharedd=shred; var sha=' shared <input type="hidden" id="who_hid_id" value="'+parsed.id+'">'+parsed.cmpny_name+"'s Event"; var pic=parsed.pic;}
date[i]=parsed.SharedDate;
events[i]='<div class="col-md-10 post" style="background:#FFF"><span class="company-logo-small"><img src="'+pic+'" style=" width: 60px; height: 60px;"></span>'
+'<span class="fullhead"><span class="posted-name"><a id="who_shred" style="color:#fff;cursor:pointer;"><input type="hidden" id="who_hid_id" value="'+parsed.id+'"><span itemprop="hiringOrganization">'+sharedd+'</span></a>'+sha+'</span></span>'
+'<span class="post-status" style="color:#fff;">'+prettyDate(parsed.SharedDate)+'</span><div class="post-inner"><div class="col-md-12"><div class="panel panel-default event">'
+'<div class="panel-heading title">'+parsed.name+'</div><ul class="list-group"><li class="list-group-item"><i class="fa fa-globe"></i>'+parsed.location+'</li>'
+'<li class="list-group-item"><i class="fa fa-calendar-o"></i>'+parsed.date+'</li><li class="list-group-item"><i class="fa fa-clock-o"></i>'+parsed.time+'</li>'
+'<li class="list-group-item"><i class="fa fa-users"></i>Attendees '+parsed.attendies+'</li></ul><ul class="list-group"><div class="panel-body"><p>'+parsed.decs+'</p>'
+'<a class="btn btn-xs btn-info pull-left" target="_blank" href="eventview?evnt_id='+parsed.evnt_id+'">View</a>  '
+'<i class="fa fa-fw fa-facebook-square" style="font-size:20px;"></i>'
+'<a class="twitter popup" href="pagelink?evnt_id='+parsed.evnt_id+'" target="_blank"><i class="fa fa-fw fa-twitter-square " style="font-size:20px;"></i></a>'
+'<a class="twitter popup" href="pagelink?evnt_id='+parsed.evnt_id+'" target="_blank">'
+'<i class="fa fa-fw fa-linkedin-square" style="font-size:20px;"></i></a><a class="twitter popup" href="pagelink?evnt_id='+parsed.evnt_id+'" target="_blank">'
+'<i class="fa fa-fw fa-google-plus" style="font-size:20px;"></i></a></div></ul><div id="img"></div><div class="clearfix"></div></div></div></div></div>';
});
}
});
-------------------------
page : get_post
--------------------
if($_POST['type']=='all13'){
$update_time=mysql_query("UPDATE `share_post` SET `sharedDate`='".$_POST['time']."' WHERE `frm_id` = 'U005114608238'");
$sql=select_query("SELECT s.id,e.u_id,e.cmpny_name,n.pro_pic as pic,l.pro_pic,l.level as lv,m.evnt_id,m.name,m.location,m.decs,m.time,
m.date,m.attendies,s.frm_id,s.is_important,s.shred,s.SharedDate,s.lvl FROM employer_info e,login l,login n,`event` m, share_post s WHERE n.u_id=s.frm_id and e.u_id=l.u_id and m.u_id=l.u_id and m.evnt_id=s.post_id and s.to_id='".$_POST['u_id']."' order by s.id desc");
$count=count($sql);
$response=array();
for($i=0;$i<$count;$i++){
array_push($response,$sql[$i]);
}
echo json_encode($response);
}
when i have inspected the error , i got something like in this screenshot
Related
I have a problem in getting the POST data from a page using ajax. In the jquery code the data is running smoothly and it will display when i alert the data. In the ajax request code the data from jquery has been successfully pass into showpercent.php file. Now the problem about showpercent.php, the data POST index percentage_id is unidentified. How can i fix this problem in getting the value of POST?
Below is the table list with button when the data is coming from.
<table>
<tr>
<td>
<button class="btn btn-info show-percentage" title="Click to add view percentages!" data-percentage_id="'.$row['hidden_id'] .'" data-toggle="show-percentage"><i class="glyphicon glyphicon-time"></i></button>
</td>
</tr>
</table>
Below is the ajax request sending the data into showpercent.php file. When I alert the percentage_id from button click the data will show in the alert and the ajax was successfully pass into specific php file which is showpercent.php.
<script>
$(document).ready(function(){
$(".show-percentage").click(function(){
var percentage_id = $(this).data('percentage_id');
alert("Ajax Landing ID "+landing_id);
$.ajax({
url: 'ajax/showpercent.php',
type: 'POST',
cache: false,
data: { percentage_id : percentage_id },
success: function(data) {
alert(data);
$('#add-percentage').modal('show');
readRecords();
},
error: function(request, status, error){
alert("Error!! "+error);
}
});
// READ recods when the button is click
readRecords();
});
function readRecords() {
$.get("ajax/showpercent.php", {}, function (data, status) {
$(".display_percentage").html(data);
});
}
});
</script>
Below is the modal having a tab will display the data from ajax request. The class display_percentage will display the current data from showpercentage.
<div id="add-percentage" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Fish Landing Percentage</h4>
</div>
<div class="modal-body">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#menu1">Add Percentage</a></li>
</ul>
<div class="tab-content">
<div id="menu1" class="tab-pane fade in active">
<br>
<div class="display_percentage"></div>
</div>
</div>
<div class="modal-footer">
<button type="button" id="primary" class="btn btn-primary" onclick="AddPercentage()"> Add Percentage </button>
<button type="button" id="danger" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
showpercent.php
This file will read by readRecords() function to display into the modal with tab class display_percentage when the button click is triggered.
This is now the problem comes, when the data was successfully pass from ajax request the data POST in the showpercent.php is not properly set and cannot proceed to the mysql process because the POST is not set.
<?php
include 'db.php';
$data = '
<table">
<thead>
<tr class="success">
<th ><center>No.</center></th>
<th ><center>Percentage ID</center></th>
<th ><center>Landing ID</center></th>
<th><center>Percentage</center></th>
<th><center>Date Added</center></th>
</tr>
</thead>';
if(isset($_POST['percentage_id'])){
$landing_id = $_POST['percentage_id'];
$query = mysqli_query($conn, "SELECT
percentage.percent_id,
percentage.landing_id,
percentage.percentage,
percentage.date_recorded
FROM
percentage
WHERE percentage.landing_id = '$landing_id'");
$number = 1;
while($row = mysqli_fetch_array($query)) {
$data .= '
<tr>
<td><center>' . $number . '</center></td>
<td><center>' . $row['percent_id'] . '</center></td>
<td><center>' . $row['landing_id'] . '</center></td>
<td><center>' . $row['percentage'] . '%</center></td>
<td><center>' . date("M. d, Y", strtotime($row['date_recorded'])) . '</center></td>
</tr>';
$number++;
}
}else{
echo 'Percentage id is not set!';
}
$data .= '
</table>';
echo $data;
?>
But in the console the ajax passing data will run smoothly.
I wish anybody will help me to fix this problem.
I read your code your showpercent.php, javascript and html and soo far and notice this
<button class="btn btn-info show-percentage" title="Click to add view percentages!" data-percentage_id="'.$row['hidden_id'] .'" data-toggle="show-percentage"><i class="glyphicon glyphicon-time"></i></button>
and check this
data-percentage_id="'.$row['hidden_id'] .'"
you're doing it wrong this is not how you put php value into html value, this will return undefined in javascript if you try to get its value so
This is why
var percentage_id = $(this).data('percentage_id');
returns undefined in javascript and php
So replace it with this
data-percentage_id="<?php echo $row['hidden_id']; ?>"
So replace your button into like this
<button class="btn btn-info show-percentage" title="Click to add view percentages!" data-percentage_id="<? echo $row['hidden_id']; ?>" data-toggle="show-percentage"><i class="glyphicon glyphicon-time"></i></button>
thanks to #Keval Mangukiya
try:
add this in your html
<button id="percentage_id" class="btn btn-info show-percentage" title="Click to add view percentages!" data-percentage_id="<?=$row['hidden_id'] ?>" data-toggle="show-percentage"><i class="glyphicon glyphicon-time"></i></button>
set the value of your percentage_id before getting it
add to your JavaScript with
$("#percentage_id]").data('percentage_id',loading_id); //setter
var percentage_id = $(this).data('percentage_id'); //getter
Iwant to insert this code
if($transaction_user_define_fields->udf_type == 'Selectbox'){
echo '<i class="fa fa-list fa-lg text-primary pull-left" data-toggle="tooltip" data-placement="right" title="View option" onclick="viewUDFOPT('.$transaction_user_define_fields->tran_udf_col_id.')"></i>';
}
inside
$this->table->add_row()
but im getting an error .please help
if($transaction_user_define_fields->udf_type == 'Selectbox'){
$this->table->add_row('<i class="fa fa-list fa-lg text-primary pull-left" data-toggle="tooltip" data-placement="right" title="View option" onclick="viewUDFOPT('.$transaction_user_define_fields->tran_udf_col_id.')"></i>');
}
This would make the tag clickable, if you want to make the entire cell clickable you will have to set it as a param in add row
as per codeigniter documentation
$cell = array('data' => 'Blue', 'class' => 'highlight', 'colspan' => 2);
$this->table->add_row($cell, 'Red', 'Green');
// generates
// <td class='highlight' colspan='2'>Blue</td><td>Red</td><td>Green</td>
I am working on AngularJS project I am using ng-repeat to show data, There is a Edit button that enable editing for particular row. On edit button click there is Save and Cancel button shows. On save button click it call $http.post to update data in database. Data are shown in gal unit and store as liter so when I click on save button it first convert to liter and then store in db.
Now the problem is when I click on Save button for once it work correctly, But when I click twice on Save button it convert gal -> liter -> liter and then save to db.
So I want to do is if $http request is already in process then do not accept another $http request.
I have tried to disable the button but still it is clickable.
HTML:
<div class="taxi_output" ng-repeat="item in vmDosings.data track by $index" >
<div class="row">
<div class="col-lg-4 text-center one" ng-bind="item.dos_nr"></div>
<div class="col-lg-4 text-center two">
<div ng-if="item.enableContent">
<input id="{{$index}}" class="font-size input-{{$index}}" ng-class="{ 'error' : vmDosings.error.level || vmDosings.error.undef || vmDosings.error.exist }" type="text" ng-model="item.level" ng-change="itemChanges(item)" ng-disabled="!item.enableContent"/> {{::$root.getEinheiten($root.GlobalData.config.volumemessurement)}}
</div>
<div ng-if="!item.enableContent" >
<p class=""> {{ item.level + ' ' + $root.getEinheiten($root.GlobalData.config.volumemessurement)}} </p>
</div>
</div>
<div class="col-lg-4" ng-if="item.enableContent == false" style="vertical-align: middle">
<a class="btn" ng-click="enableContent(item, $index)" event-focus="click" event-focus-id="{{$index}}" tooltip-placement="bottom" tooltip="{{::$root.getLabel('edit')}}">
<i style="cursor:pointer;" class="fa fa-edit fa-2x"></i>
</a>
<a class="btn" ng-if="vmDosings.data.length > 1" ng-click="removeFromList(item, $index)" tooltip-placement="bottom" tooltip="{{::$root.getLabel('delete')}}">
<i style="cursor:pointer;" class="fa fa-trash fa-2x"></i>
</a>
</div>
<div class="col-lg-4" ng-if="item.enableContent == true">
<a class="btn" ng-click="saveChanges(item, $index)" tooltip-placement="bottom" tooltip="{{::$root.getLabel('save')}}">
<i style="cursor:pointer;" class="fa fa-save fa-2x"></i>
</a>
<a class="btn" ng-click="removeFromList(item, $index)" tooltip-placement="bottom" tooltip="{{::$root.getLabel('delete')}}">
<i style="cursor:pointer;" class="fa fa-trash fa-2x"></i>
</a>
<a class="btn" ng-click="restoreChanges(item)" tooltip-placement="bottom" tooltip="{{::$root.getLabel('reset')}}">
<i style="cursor:pointer;" class="fa fa-remove fa-2x"></i>
</a>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<div ng-if="item.enableContent && vmDosings.validate == false">
<div class="panel panel-danger" style="margin-top:5px; margin-bottom:0px;">
<div class="panel-heading" style="padding:0">
<ul style="padding: 5px 0px 5px 30px;">
<li ng-if="vmDosings.error.level" ng-bind="getLabel('only_floats_with_one_digit')"></li>
<li ng-if="vmDosings.error.undef" ng-bind="getLabel('inputs_empty_not_allowed')"></li>
<li ng-if="vmDosings.error.exist" ng-bind="getLabel('data_already_exist')"></li>
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="hr-line-dashed"></div>
</div>
AngulrJS:
Enable Edit Mode:
$scope.enableContent = function(data, $index) {
angular.forEach(vmDosings.data, function(value, key) {
vmDosings.data[key].enableContent = (value.id == data.id ? true : false );
});
$timeout(function () {
$('.input-'+ $index).focus();
$('.input-'+ $index).val($('.input-'+ $index).val());
});
}
save button click:
$rootScope.GlobalData.config.volumemessurement get the id of unit
$rootScope.calcunits(9, id, data['level']); is a function for convert
$scope.saveChanges = function(data) {
var id = $rootScope.GlobalData.config.volumemessurement;
data['level'] = $rootScope.calcunits(id, 9, data['level']);
checkValues(data);
var checked = true;
for (i in vmDosings.error) {
if (vmDosings.error[i]) {
checked = false;
vmDosings.validate = false;
break;
}
}
if(checked == true) {
DosingsServices.saveChanges(data).then(function (result) {
if( result.data.message == 'success' && result.data.status == 200) {
DosingsServices.getDosings($stateParams.taxi_id).then(function (result) {
//vmDosings.data = result.data.dosings
var data = result.data.dosings;
var id = $rootScope.GlobalData.config.volumemessurement;
var i = 0;
for(i = 0; i <= data.length; i++) {
angular.forEach(data[i], function(value, key){
if(key == "level")
data[i][key] = $rootScope.calcunits(9, id, value)
});
}
vmDosings.data = data;
});
}
else if( result.data.message == 'Data Already Exist') {
data['level'] = $rootScope.calcunits(9, id, data['level']);
vmDosings.error.exist = true;
vmDosings.validate = false;
}
});
}
}
What you need is interceptors method of $httpProvider. It give you full control over any http call within Angular scope ( request,requestError,response,responseError methods).
If service call is already in progress you can skip next call or put it in a queue to call once you get response from previous call any other thing you want to do
// register the interceptor as a service
$provide.factory('myHttpInterceptor', function($q, dependency1, dependency2) {
return {
// optional method
'request': function(config) {
// do something on success
return config;
},
// optional method
'requestError': function(rejection) {
// do something on error
return $q.reject(rejection);
},
// optional method
'response': function(response) {
// do something on success
return response;
},
// optional method
'responseError': function(rejection) {
// do something on error
return $q.reject(rejection);
}
};
});
$httpProvider.interceptors.push('myHttpInterceptor');
Set a flag var inProgress = true; before your post method. Check on if this flag is set before you post. Set flag to false when post method is finished (finally).
You can also use this flag to enable/disable save button.
Hello I'm trying to delete a row in the database using ajax post but the problem is that the row gets deleted only once per page load. The row get detach from the HTML DOM everything I press the delete button, but the database only deletes one record. I want to delete therecord in the database every time I press the delete button. How can I achieve this ?
My view
<tbody id="tbody"><?php
$count = 1;
foreach($rows as $row):?>
<tr>
<td><?=$count?></td>
<td><a href="basic_table.html#">
<?=$row->FirstName." ".$row->LastName?></a>
</td>
<td class="hidden-phone"><?=$row->Email?></td>
<td><?=$row->Password?></td>
<td><span class="label label-warning label-mini">
<?=date("m/d/Y", strtotime($row->Created))?></span>
</td>
<td>
<button class="btn btn-success btn-xs">
<i class="fa fa-check"></i></button>
<button class="btn btn-primary btn-xs">
<i class="fa fa-pencil"></i>
</button>
<button id="delete" data-id="<?=$row->id?>"
data-url="<?=base_url()?>" class="btn btn-danger
btn-xs"><i class="fa fa-trash-o "></i>
</button>
</td>
</tr><?php
$count++;
endforeach?>
</tbody>
script
$(document).ready(function()
{
$("#tbody").on('click','#delete', function()
{
var id = $("#delete").data("id");
var url = $("#delete").data("url");
$.post(url + "users/delete", { id : id, cache: false } , function()
{
},"json");
$(this).closest('tr').detach();
});
});
Please give the codeigniter controller script
You must change to anchor tag and add preventDefault() to prevent reloading page
$(document).ready(function(){
$("#tbody").on('click','#delete', function(e){
//You must add e.preventDefault() to avoid reloading page
e.preventDefault();
var id = $("#delete").data("id");
var url = $("#delete").data("url");
$.post(url + "users/delete", { id : id, cache: false } , function(){
},"json");
$(this).closest('tr').detach();
});
});
i am trying to pass an id in the checkbox while generating datatables,My codes are as follows
Controller
public function list_view() {
$this->datatables->select('c.id,,c.image,c.first_name,c.email_primary,c.contact_mobile,c.contact_home,cn.country_name,c.unique_id,c.title')
->from('contact c')
->join('country cn','cn.id=c.country_id','left');
$this->datatables->add_column('action', '<input id="list-chk_" class="top-label" type="checkbox" value=c.id />', 'id');
$this->datatables->add_column('sync', '<span class="list-sync" ></span>', 'c.id');
$this->datatables->add_column('email', '<span class="list-mail" ></span>', 'c.id');
echo $this->datatables->generate('json');
}
I just want to pass c.id along with the checkbox,as I need to have further manipulation using that id in datatables,
Thank You .
You can just pass the variable as {{ c.id }}
Example:
$result = DB::table('users')
->select('users.id as id','users.first_name', 'users.last_name', 'users.email', 'users.username', 'users.activated');
return Datatables::of($result)
->add_column('actions', '<a aid="{{ $id }}" style="cursor: pointer;" class="edit_admin" data-toggle="modal" data-target="#edit_admin_modal" title="Edit Admin" ><i class="fa fa-pencil"></i></a> <a style="cursor: pointer;" aid="{{ $id }}" class="delete_admin" data-toggle="modal" data-target="#delete_admin_modal" title="Remove Admin" ><i class="fa fa-times-circle"></i></a> <a aid="{{ $id }}" style="cursor: pointer;" class="enable_disable_admin" title="Enable/Disable Admin" ><i class="fa fa-check-circle-o"></i></a>')
->remove_column('id')
->make();