How to add pagination to ajax results in wordpress - ajax

i want to paginate my ajax search results in ajax pagination
can anyone help to paginate this i try to search google but i dont found anything. i found more information about wp_query but thist data is not for me because i dont use posts
My ajax function in function.php for get data from table:
add_action( 'wp_ajax_search_ajax_call', 'search_ajax_call' );
add_action( 'wp_ajax_nopriv_search_ajax_call', 'search_ajax_call' );
function search_ajax_call(){
$country=$_POST['country'];
$date_start=$_POST['date_start'];
$date_end=$_POST['date_end'];
$wm=$_POST['wm'];
if ($country) {
$searchkeys.=" AND country='".$country."'";
}
if ($date_start) {
$searchkeys.=" AND date_start>".$date_start;
}if ($date_end) {
$searchkeys.=" AND date_end<".$date_end;
}if ($wm) {
$searchkeys.=" AND wm='".$wm."'";
}
global $wpdb;
$query = "SELECT fe.id, fe.form_id,fe.datestamp, fe.status, MAX(CASE WHEN fev.slug = 'avatar' THEN fev.value END) as avatar, MAX(CASE WHEN fev.slug = 'user_name' THEN fev.value END) as user_name, MAX(CASE WHEN fev.slug = 'message' THEN fev.value END) as message, MAX(CASE WHEN fev.slug = 'date_end' THEN fev.value END) as date_end, MAX(CASE WHEN fev.slug = 'date_start' THEN fev.value END) as date_start, MAX(CASE WHEN fev.slug = 'country' THEN fev.value END) as country, MAX(CASE WHEN fev.slug = 'tel' THEN fev.value END) as tel, MAX(CASE WHEN fev.slug = 'email' THEN fev.value END) as email, MAX(CASE WHEN fev.slug = 'age' THEN fev.value END) as age, MAX(CASE WHEN fev.slug = 'city' THEN fev.value END) as city, MAX(CASE WHEN fev.slug = 'wm' THEN fev.value END) as wm FROM wp_cf_form_entries fe INNER JOIN wp_cf_form_entry_values fev ON fev.entry_id = fe.id GROUP BY fe.id, fe.form_id, fe.status HAVING fe.id>'0' ".$searchkeys."";
$items_per_page = 10;
$page = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1;
$offset = ( $page * $items_per_page ) - $items_per_page;
$total_query = "SELECT COUNT(1) FROM (${query}) AS combined_table";
$total = $wpdb->get_var( $total_query );
$result = $wpdb->get_results( $query.' ORDER BY id DESC LIMIT '. $offset.', '. $items_per_page, OBJECT );
if (!$result) {
echo "Нет результатов";
}
foreach( $result as $results ) {
if ( $post = get_page_by_path( $results->country, OBJECT, 'country' ) )
$id = $post->ID;
else
$id = 0;
?>
<style type="text/css">
#searchresults .row div{
font-size: 20px;
line-height: 1.5;
color: white;
}
#searchresults img {
max-height: 250px;
}
</style>
<div class="row ">
<div class="col-md-6 col-sm-12 data-traveler">
<div><span>Имя: </span><?=$results->user_name;?></div>
<div><span>Возвраст: </span><?=$results->age;?></div>
<div><span>Ищет попутчика(Пол): </span><?=$results->wm;?></div>
<div><span>Страна отдыха: </span><?=get_the_title($id);?></div>
<div><span>Дата поездки: </span><?=$results->date_start;?></div>
<div><span>Email: </span><?=$results->email;?></div>
<div><span>Тел: </span><?=$results->tel;?></div>
<div><span>Cообщение: </span><?=$results->message;?></div>
</div>
<div class="col-md-6 col-sm-12"><img src="<?=$results->avatar;?>"></div>
<div class="col-md-12 col-sm-12 data-traveler">
<div class="date"><span>Дата размещение: </span><?=$results->datestamp;?></div>
</div>
</div>
<?php
}
echo paginate_links( array(
'base' => add_query_arg( 'cpage', '%#%' ),
'format' => '',
'prev_text' => __('«'),
'next_text' => __('»'),
'total' => ceil($total / $items_per_page),
'current' => $page
));
die; // даём понять, что обработчик закончил выполнение
}
My javascript for calling ajax function from wp-admin-ajax.php:
<script>
jQuery(function($){
$('#fld_551620_1').click(function(){
$('#searchresults').html('');
var country = document.getElementById("fld_8091734_1");
var date_start =$('#fld_7900131_1').val();
var date_end =$('#fld_6539646_1').val();
var wm =$( "input[name='fld_3061011']:checked" ).val();
$.ajax({
url:"<?php bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php",
type: 'POST',
data: {
action:'search_ajax_call',
country: country.options[country.selectedIndex].value,
date_start: date_start,
date_end: date_end,
wm: wm,
},
beforeSend: function() {
$('#loader').show();
},
complete: function() {
$('#loader').hide();
},
success: function( data ) {
$('#searchresults').html(data);
}
});
// если элемент – ссылка, то не забываем:
// return false;
});
});
</script>

Related

(Codeigniter) Echo result in view automatic insert to database

I want echo from if/else conditions (NEW, ALERT, ACTIVE, EXPIRED) automatic input to tr_status column in database. What should I do?
column picture phpmyadmin
<td>
<?php
$today = Date("Y-m-d");
$months = Date("Y-m-d", strtotime('+180 days'));
if ($t->tr_no == NULL) {
echo '<span style="color: #20B2AA; font-weight: bold; ">NEW</span>';
}
elseif ($t->tr_exp <= $today) {
echo '<span style=" color: red; font-weight: bold; ">EXPIRED</span>';
}
elseif ($t->tr_exp <= $months) {
echo '<span style="font-weight: bold; color: ORANGE;">ALERT</span>';
}
else {
echo '<span style="font-weight: bold; color: #4DBE24;">ACTIVE</span>';
}
?>
</td>
you need to create a function inside the contoller before load the view file
example :
$today = Date("Y-m-d");
$months = Date("Y-m-d", strtotime('+180 days'));
if ($t->tr_no == NULL) {
$object = array('tr_status' => 'NEW');
}elseif ($t->tr_exp <= $today) {
$object = array('tr_status' => 'EXPIRED');
} else {
$object = array('tr_status' => 'ACTIVE');
}
$this->db->insert('Table', $object);

daterange with timerange using codeigniter 3 and ajax

I have a daterange picker and it is fully working. However, I have a new target which is daterange with timepicker. But the thing is I don't know how to implement it like what I did on my daterange without timepicker. Is there any way where I can implement it? I have provided my codes below of my fully working daterange picker. I have provided also my screenshot of my current daterange and my target daterange with timepicker. Thank you in advance.
HTML:
<div class="img-fluid">
<div class="input-group">
From:
<input type="date" class="mr-4" id="from" name="from">
To:
<input type="date" id="to" name="to" style="margin-right:50px;">
</div>
</div>
<div class="tab-pane fade show active" id="custom-tabs-two-1" role="tabpanel" aria-labelledby="custom-tabs-two-1-tab">
<table id="testing" class="table-striped table table-head-fixed" style="min-width:1000px; width:100%;">
<thead class="" style="background-color: #404040; color: white;">
<tr>
<th scope="col"><i class="fas fa-list-ol mr-2"></i>Transaction ID</th>
<th scope="col"><i class="fas fa-list-ol mr-2"></i>Reference No.</th>
<th scope="col"><i class="far fa-calendar-alt mr-2"></i>Date Requested</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
Script & Ajax:
var save_method; //for save method string
var table;
var base_url = '<?php echo base_url();?>';
$(document).ready(function() {
//datatables
var table = $('#testing').DataTable({
dom: 'lBfrtip',
buttons: [
'print', 'csv', 'copy', 'excel', 'pdfHtml5'
],
"processing": false, //Feature control the processing indicator.
"serverSide": true, //Feature control DataTables' server-side processing mode.
"order": [], //Initial no order.
// Load data for the table's content from an Ajax source
"ajax": {
"url": "<?php echo site_url('controller/ajax_list')?>",
"type": "POST",
"data": function ( data ) {
data.from = $('#from').val();
data.to = $('#to').val();
},
},
//Set column definition initialization properties.
"columnDefs": [
{
"targets": [ 0 ], //first column
"orderable": false, //set not orderable
},
{
"targets": [ -1 ], //last column
"orderable": false, //set not orderable
},
],
});
setInterval( function () {
testing.ajax.reload(null,false);
}, 1000);
Controller:
public function ajax_list()
{
$list = $this->repo->admin();
$data = array();
$no = $_POST['start'];
foreach ($list as $person) {
$no++;
$row = array();
$row[] = $person->transID;
$row[] = $person->refNumber;
$row[] = $person->dateRequested;
$data[] = $row;
}
$output = array(
"draw" => $_POST['draw'],
"recordsTotal" => $this->repo->showing_pending(),
"recordsFiltered" => $this->repo->count_filtered(),
"data" => $data,
);
//output to json format
echo json_encode($output);
}
}
Model:
var $table = 'ca';
var $column_order = array(null,'transID','dateRequested','refNumber');
var $order = array('transID' => 'desc');
var $column_search = array('transID','dateRequested','refNumber');
//set column field database for datatable orderable //set column field database for datatable searchable just firstname , lastname , address are searchable var $order = array('id' => 'desc'); // default order
private function _get_datatables_query()
{
if($this->input->post('from')){
$this->db->where('dateCre >=', $this->input->post('from'));
$this->db->where('dateCre <=', $this->input->post('to'));
}
$this->db->from('ca');
$i = 0;
foreach ($this->column_search as $item)
{
if($_POST['search']['value'])
{
if($i===0) // first loop
{
$this->db->group_start();
$this->db->like($item, $_POST['search']['value']);
}
else
{
$this->db->or_like($item, $_POST['search']['value']);
}
if(count($this->column_search) - 1 == $i)
$this->db->group_end();
}
$i++;
}
if(isset($_POST['order']))
{
$this->db->order_by($this->column_order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
}
else if(isset($this->order))
{
$order = $this->order;
$this->db->order_by(key($order), $order[key($order)]);
}
}
function admin()
{
$this->_get_datatables_query();
if($_POST['length'] != -1)
$this->db->limit($_POST['length'], $_POST['start']);
$query = $this->db->get();
return $query->result();
}
public function showing_pending()
{
$this->db->from($this->table);
return $this->db->count_all_results();
}
function count_filtered()
{
$this->_get_datatables_query();
$query = $this->db->get();
return $query->num_rows();
}
}
What is your exact error? I think that you need to sanitize your post values before the query.
Change This:
$this->db->where('dateCre >=', $this->input->post('from'));
To this (please select the correct format in your case)
$from_date = DateTime::createFromFormat('d/m/Y h:m:s', $this->input->post('from'));
$this->db->where('dateCre >=', $from_date->format('Y-m-d h:m:s'));
Do it also with the "post('to')" value.

woocommerce product sort order change by our own weight value or menu order

I need to add a specified value or weight for a product so that product will display as per order on the woocommerce shop page. I think this can be done by product bulk edit. But not sure is it right or any conflict may arise in the future. can anyone suggest how I a custom sort function as per a given value for the bulk products? Currently, the drag and drop method is difficult in the case of thousand of products.
add_action( 'woocommerce_product_bulk_edit_start', 'custom_field_product_bulk_edit', 10, 0 );
function custom_field_product_bulk_edit() {
?>
<div class="inline-edit-group">
<label class="alignleft">
<span class="title"><?php _e('Custom Sort Weight', 'woocommerce'); ?></span>
<span class="input-text-wrap">
<select class="change_t_dostawy change_to" name="change_t_dostawy">
<?php
$options = array(
'' => __( '— No change —', 'woocommerce' ),
'1' => __( 'Change to:', 'woocommerce' ),
);
foreach ( $options as $key => $value ) {
echo '<option value="' . esc_attr( $key ) . '">' . $value . '</option>';
}
?>
</select>
</span>
</label>
<label class="change-input">
<input type="text" name="_t_dostawy" class="text t_dostawy" placeholder="<?php _e( 'Enter Weight Here ', 'woocommerce' ); ?>" value="" />
</label>
</div>
<?php
}
// Save the custom fields data when submitted for product bulk edit
add_action('woocommerce_product_bulk_edit_save', 'save_custom_field_product_bulk_edit', 10, 1);
function save_custom_field_product_bulk_edit( $product ){
if ( $product->is_type('simple') || $product->is_type('external') ){
$product_id = method_exists( $product, 'get_id' ) ? $product->get_id() : $product->id;
if ( isset( $_REQUEST['_t_dostawy'] ) ){
// update_post_meta( $product_id, 'menu_order', sanitize_text_field( $_REQUEST['_t_dostawy'] ) );
$arg=array('ID' => $product_id,'menu_order' => $_REQUEST['_t_dostawy']);
$result = wp_update_post($arg);
}
}
}
I have added an option on quick edit and then update the menu order value by ajax. so that all the product having same menu order will be displayed on same row.But this is not a correct way.
So I have do other stuff that added text box in the product listing and where we can add a menu order for product.
//
Add product new column in administration
add_filter( 'manage_edit-product_columns', 'woo_product_weight_column', 20 );
function woo_product_weight_column( $columns ) {
$columns['sort_weight'] = esc_html__( 'Weight', 'woocommerce' );
return $columns;
}
// Populate weight column
add_action( 'manage_product_posts_custom_column', 'woo_product_weight_column_data', 2 );
function woo_product_weight_column_data( $column ) {
global $post;
if ( $column == 'sort_weight' ) {
$postval = get_post( $post->ID);
$menu_order_new = $postval->menu_order;
?>
<input type="text" name="menuorder" id="id_<?php echo $post->ID;?>" data-productid="<?php echo $post->ID;?>" value="<?php echo $menu_order_new; ?>" class="menuorder"/>
<?php
}
}
add_action('admin_head', 'my_column_width');
function my_column_width() {
echo '<style type="text/css">';
echo 'table.wp-list-table .column-sort_weight { width: 101px; text-align: left!important;padding: 5px;}';
echo 'table.wp-list-table .column-wpseo-score { width: 101px; text-align: left!important;padding: 5px;}';
echo'.menuorder{ width: 101px; }';
echo '</style>';
}
// this code adds jQuery script to website footer that allows to send AJAX request
add_action( 'admin_footer', 'misha_jquery_event' );
function misha_jquery_event(){
echo "<script>jQuery(function($){
var weight_val;
var pr_id;
jQuery('.menuorder').on('input', function(){
weight_val = $(this).val();
pr_id=$(this).attr('data-productid');
var dataVariable = {
'action': 'productmetasave',
'product_id': pr_id,
'value':weight_val
};
jQuery.ajax({
url: ajaxurl,
type: 'POST',
data: dataVariable,
success: function (response) {
if(response==1){
location.reload(true);
}else{
console.log('Failed To update menu-order ');
}
}
});
});
});</script>";
}
// this small piece of code can process our AJAX request
add_action( 'wp_ajax_productmetasave', 'misha_process_ajax' );
function misha_process_ajax(){
if($_POST['product_id'] && $_POST['value'] ){
$arg=array('ID' => $_POST['product_id'],'menu_order' => $_POST['value']);
$rs = wp_update_post($arg);
if($rs){
echo "1";
}else{
echo "0";
}
}
die();
}

Table inside a datatable cell laravel 5.2

I am using laravel 5.2 framework. I have successfully implemented datatables. By application design requirement, how to implement tables within the datatable cell?
Its not really directly possible unless you define your own table and style it with css as follows
styes for my inner table defined on my view
<style type="text/css">
h3 {
color: steelblue;
}
.subtabletable {
display: table;
width: 100%;
}
.subtable .row {
display: table-row;
}
.subtable .header {
font-weight: bold;
}
.subtable .cell {
display: table-cell;
padding: 5px;
}
</style>
Definition of my table in Html
<table id="example" class="display responsive nowrap" cellspacing="0" width="100%">
My javascript
$(document).ready(function () {
var request = $.ajax({
url: "sort_respones",
type: "GET",
dataType: "html"
});
request.done(function(msg){
dynamicdatatable(msg);
});
});
function dynamicdatatable(mydata){
var myData=JSON.parse(mydata) ;
console.log(myData);
var myColumns = [
{
title : "Employee",
data : "question"
},
{
title : "Type",
data : "response_type"
},
{
title : "Responses",
data : null,
render : function (data, type, row, meta) {
var subtableHtml = "<div class='subtable'>";
subtableHtml += "<div class='row header'><span class='cell'>Response</span><span class='cell'>Occurances</span></div>";
for (var i = 0; i < data.projects.length; i++) {
subtableHtml += "<div class='row'>";
subtableHtml += "<span class='cell'>" + data.projects[i].project + "</span>";
subtableHtml += "<span class='cell'>" + data.projects[i].role + "</span>";
subtableHtml += "</div>";
};
subtableHtml += "</div>";
return subtableHtml;
}
}
];
$('#example').dataTable({
searching: false,
paging: false,
data : myData,
columns : myColumns,
dom: 'Bfrtip',
buttons: [
'copyHtml5',
'excelHtml5',
'csvHtml5',
'pdfHtml5'
]
});
}
My controller function
function sort_respones(Request $request){
$results = DB::select( DB::raw("SELECT
questions.id,
questions.question,
questions.client_id,
surveys_session_answer_transactions.created_at,
surveys_session_answer_transactions.answer_text,
surveys_session_answer_transactions.answer_id,
surveys_session_answer_transactions.question_text,
questions.response_type_id,
Count(surveys_session_answer_transactions.answer_id) AS Occurances,
checkresponses.response,
radioresponses.response,
rating_bar_responses.maximum_value,
response_types.response_type
FROM
questions
INNER JOIN surveys_session_answer_transactions ON surveys_session_answer_transactions.question_id = questions.id
LEFT OUTER JOIN checkresponses ON checkresponses.question_id = surveys_session_answer_transactions.question_id AND checkresponses.id = surveys_session_answer_transactions.answer_id
LEFT OUTER JOIN rating_bar_responses ON rating_bar_responses.question_id = surveys_session_answer_transactions.question_id
LEFT OUTER JOIN radioresponses ON radioresponses.question_id = surveys_session_answer_transactions.question_id AND radioresponses.id = surveys_session_answer_transactions.answer_id
INNER JOIN response_types ON surveys_session_answer_transactions.response_type_id = response_types.type_id
where questions.client_id=:somevariable
GROUP BY
surveys_session_answer_transactions.question_id,
surveys_session_answer_transactions.answer_id"), array(
'somevariable' => "2",
));
//echo '<pre>'.print_r($results,1) .'</pre>';
// echo '<pre>';
// var_dump($results);
// echo '</pre>';
$new_question=0;
$dataUsage=[];
$final_array=[];
$responses=[];
$old_response="";$old_response_type="";
foreach ($results as $key) {
# code...
if ($new_question!=$key->id) {
# code...
if (isset($dataUsage[0])) {
# code...
array_push($final_array, array('question' =>$old_response,'response_type'=>$old_response_type,'projects' => ($responses)));
$responses=[];
//array_push($final_array, $dataUsage);
$dataUsage=[];
$responses_string="<table>";
}
array_push($dataUsage, array('question' => $key->question,'response_type'=>$key->response_type ));
$old_response=$key->question;
$old_response_type=$key->response_type;
// $responses_string='<TR><TD>'.$key->answer_text.'</TD><TD>: '.$key->Occurances.'<br></TD></TR>';
array_push($responses,array('project' => $key->answer_text, 'role' => $key->Occurances ));
}else{
// $responses_string=$responses_string.'<TR><TD>'.$key->answer_text.'</TD><TD> :'.$key->Occurances.'<br></TD></TR>';
array_push($responses,array('project' => $key->answer_text, 'role' => $key->Occurances ));
}
$new_question=$key->id;
}
array_push($final_array, array('question' =>$old_response,'response_type'=>$old_response_type,'projects' => ($responses)));
// echo '<pre>';
// var_dump($final_array);
// echo '</pre>';
// echo json_encode( array('data' =>$final_array ));
// $myData = array( array('employee' =>'Bob Smith', 'projects'=> array(array('project'=>'Alpha', 'role'=>'leader' ), array('project'=>'Alpha1', 'role'=>'leader1' ),array('project'=>'Alpha', 'role'=>'leader' ))));
echo json_encode($final_array);
}
of course don't forget the necessary routes

When I update data it is not updating correct Codeigniter

I am trying to update some calendar data to database. But each time I update it updates my day column it updates with 18<span class="label label-danger" xss=removed>Notice</span> It should only update day column with number 18
I am not sure why the $this->input->post('day') has added the span information.
Here is my var dump.
array (size=2)
17 => string 'Event 17-12-15' (length=14)
'18<span class="label label-danger" xss=removed>Notice</span>' => string '26' (length=2)
Quesions:
How is it possible to only update day column with number and not with span?
What could be causing it to have span updated with number?
Tried:
$this->input->post('day', TRUE)
$this->input->post('day', FALSE)
Controller
Note: I am using models functions on controller just for testing
<?php
class Calendar extends MX_Controller {
public function __construct() {
parent::__construct();
$this->load->model('dashboard/model_calendar');
$this->load->library('calendar');
}
public function index() {
if ($this->uri->segment(3) == FALSE) {
$year = date('Y');
} else {
$year = $this->uri->segment(3);
}
$data['year'] = $year;
if ($this->uri->segment(4) == FALSE) {
$month = date('m');
} else {
$month = $this->uri->segment(4);
}
$data['month'] = $month;
var_dump($this->get_calendar_data($year, $month));
$prefs = array(
'start_day' => 'monday',
'show_next_prev' => true,
'day_type' => 'long',
'next_prev_url' => base_url('dashboard/calendar')
);
$prefs['template'] = '
{table_open}<table border="0" cellpadding="0" cellspacing="0" class="table table-striped table-bordered calendar">{/table_open}
{heading_row_start}<tr>{/heading_row_start}
{heading_previous_cell}<th><i class="fa fa-chevron-left fa-2x "></i></th>{/heading_previous_cell}
{heading_title_cell}<th class="text-center" colspan="{colspan}">{heading}</th>{/heading_title_cell}
{heading_next_cell}<th class="text-right"><i class="fa fa-chevron-right fa-2x"></i></th>{/heading_next_cell}
{heading_row_end}</tr>{/heading_row_end}
{week_row_start}<tr>{/week_row_start}
{week_day_cell}<td>{week_day}</td>{/week_day_cell}
{week_row_end}</tr>{/week_row_end}
{cal_row_start}<tr class="days">{/cal_row_start}
{cal_cell_start}<td class="day">{/cal_cell_start}
{cal_cell_content}
<div class="day_num">{day}<span class="label label-danger" style="margin-left: 10px;">Notice</span></div>
<div class="content">{content}</div>
{/cal_cell_content}
{cal_cell_content_today}
<div class="day_num highlight">{day}</div>
<div class="content">{content}</div>
{/cal_cell_content_today}
{cal_cell_no_content}<div class="day_num">{day}</div>{/cal_cell_no_content}
{cal_cell_no_content_today}<div class="day_num highlight">{day} <span class="label label-success">Current Day</span></div>{/cal_cell_no_content_today}
{cal_cell_blank} {/cal_cell_blank}
{cal_cell_end}</td>{/cal_cell_end}
{cal_row_end}</tr>{/cal_row_end}
{table_close}</table>{/table_close}
';
$this->calendar->initialize($prefs);
if ($this->input->post('day')) {
$this->update_calendar_event($year, $month);
}
$data = $this->get_calendar_data($year, $month);
$data['calendar'] = $this->calendar->generate($year, $month, $data);
$this->load->view('dashboard/calender_view', $data);
}
public function update_calendar_event($year, $month) {
$date = $year .'-'. $month .'-'. $this->input->post('day');
$calendar = array(
'year' => $year,
'month' => $month,
'day' => $this->input->post('day', TRUE),
'data' => $this->input->post('data')
);
$this->db->where('date', $date);
$this->db->update('calendar', $calendar);
}
public function get_calendar_data($year, $month) {
$cell_data = array();
$this->db->select('*');
$this->db->from('calendar');
$this->db->where('year', $year);
$this->db->where('month', $month);
$query = $this->db->get();
foreach ($query->result() as $result) {
$cell_data[$result->day] = $result->data;
}
return $cell_data;
}
public function check_calendar_event($year, $month, $day) {
$date = $year .'-'. $month .'-'. $day;
$this->db->select('year, month, day');
$this->db->from('calendar');
$this->db->where('date', $date);
$results = $this->db->count_all_results();
return $results;
}
}
View
<div class="panel panel-default">
<div class="panel-heading">
<h1 class="panel-title">Calendar</h1>
</div>
<div class="panel-body">
<?php echo $calendar;?>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('.calendar .day').click(function() {
day_num = $(this).find('.day_num').html();
day_data = prompt('Enter Event', $(this).find('.content').html());
if (day_data != null) {
$.ajax({
url: window.location,
type: 'POST',
data: {
day: day_num,
data: day_data
},
success: function(msg) {
location.reload();
}
});
}
});
});
</script>
There could be couple of options why you are having this problem. to find out which one start by checking the does day_num passing to your Controller? do this:
<script type="text/javascript">
$(document).ready(function() {
$('.calendar .day').click(function() {
day_num = $(this).find('.day_num').html();
day_data = prompt('Enter Event', $(this).find('.content').html());
if (day_data != null) {
$.ajax({
url: window.location,
type: 'POST',
data: {
day: day_num,
data: day_data
},
success: function(msg) {
//location.reload(); turn off the reload for now.
alert(day_num); //what does this alert show?
}
});
}
});
});
And leave a comment on what does the alert show you? the number 18 or the whole HTML so i know how to help you..

Resources