http://ajobis.brainiacstech.com/404_override error when i pass url
when i click on apply button to send action url this message shown is 404 page not found i think it is because of use of () brakets with test work, other url which has no any special charachter is being passed successfully, my code is as under
<div id="content-wrapper" class="container">
<div class="row">
<div class="col-lg-9">
<div>
<div class="content-wrapper">
<!-- <div class="content-header">
<script>
function goBack() {
window.history.back()
}
</script>
<div class="title"><h1><a onclick="goBack()"><img src="<?php echo base_url("resources/images/back-icon.jpg"); ?>" alt="">Back to Results</a></h1></div>
</div>-->
<div class="content">
<div id="search-result-wrapper">
<div class="title" style="color: #005580;"><h1><?php echo $job->job_title; ?></h1></div>
<div>
<p><?php echo $job->job_description; ?></p>
</div>
<?php if (!empty($job->question)) { ?>
<div class="title text-blue"><h2>Application Questions</h2></div>
<div class="question-awnser">
<ul>
<?php $counter = 0; ?>
<?php foreach ($job->question as $question) { ?>
<li><?php echo $question->question;
$counter++; ?>
<span class="answers">
<input type="radio" name="answers" id="yes" value="yes">
<label id="answer_<?php echo $counter; ?>" for="yes">Yes</label>
/
<input type="radio" name="answers" id="no" value="No">
<label for="no">No</label>
</span>
</li>
<?php } ?>
</ul>
</div>
<?php } ?>
<div class="section-row">
<div class="pull-right">
<div class="pull-left">
<img src="<?php echo base_url("resources/images/apply-icon.jpg"); ?>"> Apply
</div>
<div class="pull-left" id="<?php echo $job->id; ?>">
<button onclick="save_job('<?php echo $job->id; ?>')" class="btn btn-blue"><span class="glyphicon glyphicon-save"></span> Save</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php $this->load->view('front/common/job_detail_widget'); ?>
</div>
<div class="row">
<div class="col-lg-11">
<div class="title"><h3 style="color: #0a0;">Suggested Jobs</h3></div>
</div>
</div>
<div class="suggestion-jobs"><div class="row">
<!--suggestedJobs-->
<?php if (!empty($suggestedJobs)) { ?>
<?php foreach ($suggestedJobs as $suggestedJob) { ?>
<div class="col-lg-3 suggestions">
<input type="text" id="jobid" value="<?php echo $suggestedJob->job_url; ?>" style="display: none;">
<input type="text" id="jobid" value="<?php echo $suggestedJob->id; ?>" style="display: none;">
<div class="suggestions-info"><h4><?php echo $suggestedJob->job_title; ?></h4></div>
<div class="suggestions-info"><span>Salary: </span><?php echo $suggestedJob->min_salary; ?> - to - <?php echo $suggestedJob->max_salary; ?></div>
<div class="suggestions-info"><span>Location: </span><?php echo $suggestedJob->location; ?></div>
<div class="suggestions-info"><span>Posted on: </span><?php echo $suggestedJob->start_date; ?></div>
</div>
<?php } ?>
<?php } else { ?>
No Job Found
<?php } ?>
</div>
</div>
</div><!--
<!--</div>-->
<script src="<?php echo base_url("resources/js/icheck.js"); ?>"></script>
<script type="text/javascript">
function save_job(id) {
$.ajax({
dataType: 'json',
type: 'POST',
url: base_url + 'employee/add-to-favorite',
data: {
jobId: id
},
success: function(RESP) {
if (RESP.status == 200) {
$('#' + id).html("<button class='btn btn-green' disabled='disabled'><span class='glyphicon glyphicon-save'></span> Saved</button>");
displayUIMessage(RESP.message);
}
}
});
}
function check_killer_answers() {
var count = '<?php echo $counter; ?>';
var error = 0;
for (var i = 1; i <= count; i++) {
if ($('#answer_' + i).hasClass('active')) {
} else {
error++;
}
}
if (error == 0) {
window.location.href = '<?php echo base_url('employee/confirm-apply/' . #$job->job_url); ?>';
} else {
alert('Please answer all questions to apply.');
}
}
function report(id) {
$.ajax({
dataType: 'json',
type: 'POST',
url: base_url + 'employee/report-to-admin',
data: {
jobId: id
},
success: function(RESP) {
if (RESP.status == 200) {
displayUIMessage(RESP.message);
}
}
});
}
</script>
Related
I want when user click on "more detail href". they should get this detail on modal the box.
<ul class="list-tickets">
<?php foreach ($searchFlights as $searchFlight) {
//One Way Logic
$stopInfo_O = "";
$stopCount_O = 0;
$AirlineLogo_O = $this->search_model->getAirlinelogo($searchFlight->airline_idO);
$finalDepartdate_O = $searchFlight->departure_dateO;
$DepartAirpot_O = $this->search_model->getAirportCode($searchFlight->depart_airportidO);
$totalFlightTime_O = $searchFlight->total_flighttimeO;
$finalArrivaldate_O = $searchFlight->arrival_dateO;
$totalBaggage_O = $searchFlight->baggageO;
$stopOvertime1 = $searchFlight->stopover1_staydurationO;
$className0 = $searchFlight->classNameO;
$ArrivalAirpot_O = $this->search_model->getAirportCode($searchFlight->arrival_airportidO);
$flightPrice = $searchFlight->flightPrice;
if($searchFlight->operatedby_airlineidO == "0") {
$operatedAirlinename = "";
} else {
$operatedAirlinename = $this->search_model->getAirlinename($searchFlight->operatedby_airlineidO);
}
//Stops Handling Oneway
if(empty($searchFlight->stopover1_airportidO) && empty($searchFlight->stopover2_airportidO)){ $stopInfo_O = "Direct"; }
if($searchFlight->stopover1_airportidO != 0){ $stopCount_O++; }
if($searchFlight->stopover2_airportidO != 0){ $stopCount_O++; }
if($stopCount_O>0){
$stopInfo_O .= $stopCount_O." Stop ";
//Stop oneway 1
$stopInfo_O .= $this->search_model->getAirportCode($searchFlight->stopover1_airportidO);
if($stopCount_O == 2) {
//Stop One Way 2
$stopInfo_O .= ", ".$this->search_model->getAirportCode($searchFlight->stopover2_airportidO);
}
}
?>
<li class="list-item">
<div class="list-item-inner">
<div class="list-item-main">
<!-- Oneway Section -->
<div class="list-item-top">
<div class="list-item-logo">
<img src="<?= base_url(); ?>uploads/<?php echo $AirlineLogo_O; ?>" alt="">
</div>
<div class="list-item-content">
<div class="list-item-content-left">
<!-- Final Departure Dates-->
<div class="text-bold text-base">
<?php echo $finalDepartdate_O; ?>
</div>
<!-- Departure Airport -->
<span class="small reveal-block">
<?php echo $DepartAirpot_O; ?>
</span>
</div>
<div class="list-item-content-line-wrapper small">
<!-- Total Flight Time -->
<div class="list-item-content-line-top">
<?php echo $totalFlightTime_O; ?>
</div>
<div class="list-item-content-line"></div>
<!-- Stops info -->
<div class="list-item-content-line-bottom text-primary">
<p title="<?php echo $stopOvertime1; ?>"><?php echo $stopInfo_O; ?> </p>
</div>
</div>
<div class="list-item-content-right">
<!-- Final Arrival date -->
<div class="text-bold text-base">
<?php echo $finalArrivaldate_O; ?>
</div>
<!-- Arrival Airport -->
<span class="small reveal-block">
<?php echo $ArrivalAirpot_O; ?>
</span>
</div>
</div>
</div>
</div>
<div class="list-item-footer ticket-holder-dt">
<h5 class="text-bold list-item-price"><?php echo COMMON_CurrencySymbol." ".$flightPrice;?></h5>
<span class="ticket-include"></span>
<span class="ticket-type">One way</span>
<a class="btn btn-info btn-xs btn-no-shadow" href="<?= base_url(); ?>searchflights/bookFlight?id=<?php echo $searchFlight->id; ?>">
Book Now
</a>
<br>
<a href="">
More detail <!-- I want when user click on it. they should get this detail on modal the box -->
</a>
<br>
<?php echo $className0; ?> Class
</div>
</div>
<div class="small text-gray-light list-item-subtitle">Operated by <?php echo $operatedAirlinename; ?></div>
<div class="tripbaggage">Baggage: <?php echo $totalBaggage_O; ?></div>
<?php } ?>
You can achieve this by implementing separate modal for each id inside for loop or
by implementing Ajax request to show the detail information of the corresponding id.
i have created a form for editing the record from db there is different time slots and i want to make delete function for them so i made a ajax call but am confused in URL www.hostname.com/dental/public/admin/manageschedule/1/api/ajax 404 (Not Found)
how to call ajax inside a laravel edit form
here is what i have done:
#extends('admin.layouts.app_inner')
#section('htmlheader_title')
Home
#endsection
#section('content')
#if (count($errors))
#foreach($errors->all() as $error)
<div class="alert alert-danger"><i class="fa fa-fw fa-close"></i> {{ $error }}</div>
#endforeach
#endif
#if ($message = Session::get('success'))
<div class="alert alert-success alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-check"></i>Success</h4>
{{ $message }}
</div>
#endif
<div class="box box-info">
<div class="box-header with-border">
<h3 class="box-title text-green"><b>Add Schedule</b></h3>
</div>
<!-- /.box-header -->
<!-- form start -->
<div class="box-body">
{!! Form::model($doctors, ['method' => 'PATCH','route' => ['manageschedule.update', $doctors->doctor_id],'class' => 'form-horizontal','files'=>true]) !!}
<div class="form-group">
<label class="col-md-3 control-label"> Select Doctor :</label>
<div class="col-md-5">
<select class="form-control" required name="doctor_name">
<?php $results = DB::select(DB::raw("SELECT day FROM schedule_times where doctor_id='" . $doctors->doctor_id . "' Order BY id DESC ")); ?>
<option value="{{$doctors->doctor_name}}" SELECTED="YES">{{$doctors->doctor_name}}</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label" required> Day :</label>
<div class="col-md-5">
<div class="md-checkbox-inline">
<?php $day = array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'); ?>
#foreach($day as $days)
<input name="day[]" value="<?php echo $days; ?>" type="checkbox" class="md-checkbox" <?php
foreach ($results as $row) {
if ($row->day == $days) {
echo 'checked="checked"';
} else {
}
}
?> >
<label for="checkbox7"> <?php echo $days; ?> </label>
#endforeach
</div>
</div>
</div>
<?php foreach ($results as $row) { $d=$row->day;}
$result= DB::select(DB::raw("SELECT * FROM schedule_times where doctor_id='" . $doctors->doctor_id . "' And day='".$d."' "));
?>
<div class="form-group">
<label class="col-md-3 control-label" required>Time slots</label>
<div class="col-md-6">
<table class="table table-bordered" id="employee_table" width="50%" >
<th>Start Time</th>
<th>End Time</th>
<th>Manage</th>
<?php foreach ($result as $key=>$vari) {
$id = $vari->id;
?>
<tr id="row1">
<td><div class="input-group ">
<input type="text" class="form-control" id="time" placeholder="Start Time" name="s_time[]" value="<?php echo $vari->start_time; ?>" >
<span class="input-group-addon">
<span class="glyphicon glyphicon-time"></span>
</span>
</div></td>
<td><div class="input-group ">
<input type="text" class="form-control" id="time1" placeholder="Start Time" name="e_time[]" value="<?php echo $vari->end_time; ?>" >
<span class="input-group-addon">
<span class="glyphicon glyphicon-time"></span>
</span>
</div></td>
<?php if ($key == 0) { ?>
<td><input type='button' class='fa fa-plus fa-4 btn btn-primary' value='DELETE' disabled></td>
<?php } else { ?>
<td><span class='delete' id='del_<?php echo $id; ?>'><input type='button' class='fa fa-plus fa-4 btn btn-primary' value='DELETE' id='del_<?php echo $id; ?>' ></td>
</tr>
<?php }
}
?>
</table>
<a type="button" onclick="add_rows();" class="fa fa-plus-circle btn btn-primary"> Add More Time Slots</a>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label"> Per Patient Time :</label>
<div class="col-md-5">
<div class=" input-daterange">
<input type="text" name="p_time" class="form-control" placeholder="Set per patient time" id="time1" value="<?php
echo $result[0]->p_time; ?>">
<span class="help-block"> You can set only minute </span>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Visibility :</label>
<div class="col-md-5">
<input type="radio" id="checkbox2_5" value="Yes" name="visible" class="md-radiobtn" <?php
foreach($result as $check)
{
if($check->visibility=='Yes'){ echo 'checked="checked"';}else{}
} ?> >
<label for="checkbox2_5"> Yes </label>
<input type="radio" id="checkbox2_10" value="No" name="visible" class="md-radiobtn" <?php foreach($result as $check)
{
if($check->visibility=='No'){ echo 'checked="checked"';}else{}
} ?>>
<label for="checkbox2_10"> No </label>
</div>
</div>
<br><br>
<div class="box-footer">
<button type="submit" class="btn btn-info pull-right"id="submit">Update Schedule </button>
</div>
{!! Form::close() !!}
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$(function () {
$('#time').timepicker();
})
});
</script>
<script type="text/javascript">
$(document).ready(function () {
$(function () {
$('#time1').timepicker();
})
});
</script>
<script type="text/javascript">
function add_rows()
{
$rowno = $("#employee_table tr").length;
$rowno = $rowno + 1;
$("#employee_table tr:last").after("<tr id='row" + $rowno + "'><td><div class='input-group '><input type='text' class='form-control' placeholder='Start Time' name='s_time[]' onclick=showtime('row" + $rowno + "')><span class='input-group-addon'><span class='glyphicon glyphicon-time'></span></span></div> </td><td><div class='input-group '><input type='text' class='form-control' id='time1' placeholder='End Time' name='e_time[]'><span class='input-group-addon'><span class='glyphicon glyphicon-time'></span></span></div> </td><td><input type='button' class='fa fa-plus fa-4 btn btn-primary' value='DELETE' onclick=delete_row('row" + $rowno + "')></td></tr>");
}
function delete_row(rowno)
{
$('#' + rowno).remove();
}
</script>
<script type="text/javascript">
//Variant Deleting script///
$(document).ready(function () {
// Delete
$('.delete').click(function () {
var el = this;
var id = this.id;
var splitid = id.split("_");
// Delete id
var deleteid = splitid[1];
alert('Are you sure you want to delete?');
$.ajax({
url: 'api/ajax',
type: 'delete',
data: {id: deleteid},
success: function (response) {
// Removing row from HTML Table
$(el).closest('tr').css('background', 'tomato');
$(el).closest('tr').fadeOut(800, function () {
$(this).remove();
});
}
});
});
});
</script>
<meta name="_token" content="{!! csrf_token() !!}" />
#endsection
here is my controller of api
Route::post('ajax','Controller#ajax')->name('ajax');
here is my web route:
Route::get('/', function () {
return view('auth.login');
});
Route::post('/', function () {
return view('auth.login')->with('successMsg','Please Select A role .');
});
Route::prefix('admin')->group(function() {
Route::get('/login', 'Auth\AdminLoginController#showLoginForm')->name('admin.login');
Route::post('/login', 'Auth\AdminLoginController#login')->name('admin.login.submit');
Route::get('/', 'AdminController#index')->name('admin.home');
Route::resource('managedoctor', 'AddDocController');
Route::resource('managefront', 'AddFrontController');
Route::resource('managepatient', 'AddPatientController');
Route::resource('manageschedule', 'AddScheduleController');
Route::get('/logout', 'Auth\AdminLoginController#logout')->name('admin.logout');
});
Route::prefix('doctor')->group(function() {
Route::get('/login', 'Auth\DoctorLoginController#showLoginForm')->name('doctor.login');
Route::post('/login', 'Auth\DoctorLoginController#login')->name('doctor.login.submit');
Route::get('/', 'DoctorController#index')->name('doctor.home');
Route::get('/logout', 'Auth\DoctorLoginController#logout')->name('doctor.logout');
});
Route::prefix('frontdesk')->group(function() {
Route::get('/login', 'Auth\FrontdeskLoginController#showLoginForm')->name('frontdesk.login');
Route::post('/login', 'Auth\FrontdeskLoginController#login')->name('frontdesk.login.submit');
Route::get('/', 'FrontdeskController#index')->name('frontdesk.home');
Route::get('/logout', 'Auth\FrontdeskLoginController#logout')->name('frontdesk.logout');
});
my issue is resolved now the mistake i have done is i was not using the same route group in which am calling the controller with AUTH method
Now this may sound complicated but I have a page called activation.php where after the user has registered using my reg.php page, they get sent an email with their activation link - activation.php then a get method of k to make activation.php?k=activation-code-here
I made it so it returns the status of the activation, e.g - success of error.
On my reg.php page, I want to make it so it uses ajax to open a sweetAlert popup saying 'Activation Success'. It will get the popup depending on if the users 'activ_status' changed from 0 to 1 in the database when they access the activation.php page with a correct activation key.
Here is my code :
Activation.php
<?php
include('inc/conf/db_.php');
$result = '';
if(empty($_GET['k']) || (!$_GET['k']))
{
header('Location: login.php');
exit();
$result = 'Hacker Tried Accessing Auth Page';
}
$key = mysqli_real_escape_string($con,$_GET["k"]);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php
if (!empty($key))
{
$query = "SELECT * FROM users WHERE activ_key = '$key'";
$result = mysqli_query($con,$query) or die('error');
if (mysqli_num_rows($result))
{
$row = mysqli_fetch_array($result);
if ($row['activ_status']!='1')
{
$query = "update users set activ_status='1' where activ_key='$key'";
$result = mysqli_query($con,$query) or die('error');
$result = 'Successfuly Activated, Return To Your Other Page.';
}
else
{
$result = "Account Already Activated";
}
}
else
{
$result = 'Invalid Access Token';
}
}
else
{
$result = 'Error';
}
?>
<?php include('inc/login_header.php'); ?>
<div class="accountbg"></div>
<div class="wrapper-page">
<div class="panel panel-color panel-primary panel-pages">
<div class="panel-body">
<br>
<center><div id="result"></center>
<br>
<h3 class="text-center m-t-0 m-b-30"> <span class=""><?php echo site_settings('site_name'); ?></h3>
<h4 class="text-muted text-center m-t-0"><b>Activation Status</b></h4>
<br>
<center><img src="assets/images/loading.gif"></center>
<br>
<center><div class="alert alert-info"><button type="button" class="close"></button><?php echo $result; ?></div></center>
<?php return $result; ?>
</body>
</html>
My reg.php page
<?php
include('inc/conf/db_.php');
if (session_status() == PHP_SESSION_ACTIVE) {
session_start();
}
if(isset($_SESSION['user_i']) || isset($_SESSION['login'])) {
header('Location: index.php');
exit();
}
else if (session_status() == PHP_SESSION_NONE) {
?>
<!DOCTYPE html>
<html lang="en">
<head>
<link href="assets/plugins/bootstrap-sweetalert/sweet-alert.css" rel="stylesheet" type="text/css">
<?php include('inc/login_header.php'); ?>
<div class="accountbg"></div>
<div class="wrapper-page">
<div class="panel panel-color panel-primary panel-pages">
<div class="panel-body">
<center><img src="assets/images/loading.gif" id="loading-image" style="display:none"/></center>
<h3 class="text-center m-t-0 m-b-30"> <span class=""><?php echo site_settings('site_name'); ?></h3>
<h4 class="text-muted text-center m-t-0"><b>Sign Up</b></h4>
<form id="registered_form" class="form-horizontal m-t-20">
<div class="form-group has-feedback">
<div class="col-xs-12"> <input class="form-control" name="email" type="email" required="" placeholder="Email"></div>
<span class="fa fa-envelope form-control-feedback text-muted" style="margin-top: 3%;"></span>
</div>
<div class="form-group has-feedback">
<div class="col-xs-12"> <input class="form-control" name="username" type="text" required="" placeholder="Username"></div>
<span class="fa fa-user form-control-feedback text-muted" style="margin-top: 3%;"></span>
</div>
<div class="form-group has-feedback">
<div class="col-xs-12"> <input class="form-control" name="password" type="password" required="" placeholder="Password"></div>
<span class="fa fa-lock form-control-feedback text-muted" style="margin-top: 3%;"></span>
</div>
<div class="form-group">
<div class="g-recaptcha" data-sitekey="6LeGFxYUAAAAAOqjyovTS3H0D1HS4IBgoHMvG4y_"></div>
</div>
<div class="form-group">
<div class="col-xs-12">
<div class="checkbox checkbox-primary" style="text-align: center;"> <input type="checkbox" name="checkbox" value="agree"> <label for="checkbox-signup"> I accept Terms and Conditions </label></div>
</div>
</div>
<div class="form-group text-center m-t-20">
<div class="col-xs-12"> <button class="btn btn-primary w-md waves-effect waves-light" type="submit" id="reg_button" style="width: 100%;" >Register</button></div>
</div>
<div class="form-group m-t-30 m-b-0">
<div class="col-sm-12 text-center"> Already have an account?</div>
</div>
</form>
</div>
</div>
</div>
<script src="assets/js/jquery.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<script type="text/javascript" src="assets/js/jquery.validate.js"></script>
<script src="assets/plugins/bootstrap-sweetalert/sweet-alert.min.js"></script>
<script>
$(document).ready(function()
{
jQuery.validator.addMethod("noSpace", function(value, element)
{
return value.indexOf(" ") < 0 && value != "";
}, "Spaces are not allowed");
$("#registered_form").submit(function()
{
if ($("#registered_form").valid())
{
$('#loading-image').show();
var data1 = $('#registered_form').serialize();
$.ajax({
type: "POST",
url: "inc/pgs/register.php",
data: data1,
success: function(msg)
{
$('#loading-image').hide();
console.log(msg);
if(msg == '')
{
swal({
title: "Registration Success!",
text: "Your registration was successful! Check your email and click on your activation link to be able to access your account. NOTE: Keep this page open",
type: "success",
timer: 15000,
showConfirmButton: false
});
}
else
{
swal("Registration Error!", msg, "error");
}
}
});
$.ajax({
type: "GET",
url: "activation.php",
data: data1,
success: function(msg)
{
if(msg == 'Successfuly Activated, Return To Your Other Page.')
{
swal({
title: "Activation Success",
text: "You can now login!",
type: "success",
timer: 15000,
showConfirmButton: false
});
}
}
});
}
return false;
});
});
</script>
</body>
</html>
<?php } ?>
I found a piece of code that might help me. It doesn't seem to be loading the modal up though:
$.ajax({
url: 'activation.php',
type: 'GET',
dataType: 'jsonp',
cache: 'false',
timeout: 32000,
success: function(data) {
if(data == 'Successfuly Activated, Return To Your Other Page.')
{
swal("Activation Completed!", "You can now login using the link at the bottom of the page - Already have an account?", "success")
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.log("Error[refresh]: " + textStatus);
console.log(jqXHR);
ajaxCall();
},
});
Please clearly explain the problem you are having that is preventing the code from working as you intend.
If my interpretation is correct, you want to update the registration page that user keeps open while activating in another window, and then reflect the change on the registration page using AJAX. In fact, in this case you want to send data from the server to your client (you want something to change when a change happens on the server in the database). In this case, a simple solution is to repeatedly request the status (for instance every 2 seconds) using setTimeout. Other solutions exist but are probably overkill, such as long polling or web sockets.
Hello All This is a solution for Load more posts by wordpress ajax.
First of all suppose you have section like this.
<section class="hightech-news-content" >
<div class="container">
<?php
$page_number = (get_query_var('paged')) ? get_query_var('paged') : 1;
$page_link = get_pagenum_link(9999999999);
$args = array('post_type' => 'post','posts_per_page' => 3,'paged'=>$page_number);
$the_query = new WP_Query( $args );
$max_page = $the_query->max_num_pages;
?>
<div class="row news-list-row">
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="col-lg-4 col-md-4 col-sm-6 hightech-news-list">
<div class="row hightech-news-list-row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-4 hightech-news-list-img">
<?php if(has_post_thumbnail()){ ?>
<img class="img-responsive" src="<?php echo get_the_post_thumbnail_url();?>">
<?php }else{ ?>
<img class="img-responsive" src="<?php echo get_template_directory_uri(); ?>/images/Img-1.png">
<?php } ?>
<img class="hi_img" src="<?php echo get_template_directory_uri(); ?>/images/Hi.png">
</div>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-8 hightech-news-list-content">
<h3><?php the_title(); ?></h3>
<p><?php echo substr(strip_tags($post->post_content), 0, 80)."...";?></p>
<br>
<h4>> Lee verder</h4>
</div>
</div>
</div>
<?php endwhile; ?>
<?php endif ;?>
<div class="clear"></div>
</div>
<div class="text-center loading-img">
<img id="loading-img" src="<?php echo get_template_directory_uri(); ?>/images/loading.gif" >
</div>
<div class="event-more">
<a href="javascript:void(0)" id="load-more" onclick="loadMoreFun();" data-pagenumber="<?php echo $page_number; ?>" data-maxpage="<?php echo $max_page; ?>" data-pagelink="<?php echo $page_link; ?>">
<h4><img src="<?php echo get_template_directory_uri(); ?>/images/next.png" >Bekijk de agenda</h4>
</a>
</div>
</div>
</section>
Now for loadMoreFun() we can add a script like this.
<script type="text/javascript">
function loadMoreFun() {
var next_page = jQuery('#load-more').data("pagenumber");
var max_page = jQuery('#load-more').data("maxpage");
var next_page_url = jQuery('#load-more').data("pagelink");
var $load_more_btn = jQuery(this);
var request_data = jQuery(this).attr('pagenumber');
next_page++;
jQuery('#load-more').data('pagenumber',next_page);
var next_link = next_page_url.replace(/\d+(\/)?$/, next_page + '$1');
if(next_page <= max_page) {
var post_type = 'post';
$.ajax({
type : 'POST',
url : next_link,
cache: false,
beforeSend: function(){
jQuery('.loading-img').show();
},
complete: function(){
jQuery('.loading-img').hide();
},
success: function(response) {
if (jQuery(response).find('.hightech-news-list')){
var newElems = jQuery(response).find('.news-list-row').html();
jQuery('.news-list-row').append(newElems);
if(next_page == max_page){
jQuery('#load-more').text('No More News Available');
}
} else{
}
}
});
}
}
</script>
Hope it will be helpful for everyone.Please let me know it another help required.
I copied estimatePostAction and made estimateAjaxPostAction (overriding core - I did not hack the core). The controller action works as well (class Mage_Checkout_CartController).
Now I want to get/create a block for replacing shipping block after estimate shipping with ajax. I tried this:
public function estimateAjaxPostAction()
{
$country = (string) $this->getRequest()->getParam('country_id');
$postcode = (string) $this->getRequest()->getParam('estimate_postcode');
$city = (string) $this->getRequest()->getParam('estimate_city');
$regionId = (string) $this->getRequest()->getParam('region_id');
$region = (string) $this->getRequest()->getParam('region');
$this->_getQuote()->getShippingAddress()
->setCountryId($country)
->setCity($city)
->setPostcode($postcode)
->setRegionId($regionId)
->setRegion($region)
->setCollectShippingRates(true);
$this->_getQuote()->save();
//$this->_goBack();
$this->loadLayout();
$block = $this->getLayout()->createBlock('Mage_Checkout_Block_Cart_Shipping','checkout.cart.shipping.ajax',array('template' => 'checkout/cart/shipping.phtml'));
if($block) {
$response = array();
$response['shipping'] = $block->toHtml();
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
}
}
The block checkout.cart.shipping.ajax was created. But toHtml() returns nothing.
My JSON returns:
{"shipping":""}
Why toHtml method doesn't work?
Edit: My block code (checkout/cart/shipping.phtml)
<?php /** #var $this Mage_Checkout_Block_Cart_Shipping */ ?>
<div class="row contem-shipping">
<div class="col-xs-10 shipping">
<div class="text-ship">
<h2><?php echo $this->__('Calcular o frete:') ?></h2>
<p><?php echo $this->__('Insira o CEP do endereço<br />no campo ao lado.') ?></p>
</div>
<div class="shipping-form">
<form action="<?php echo $this->getUrl('checkout/cart/estimatePost') ?>" method="post" id="shipping-zip-form">
<ul class="form-list">
<li class="no-display">
<div class="input-box">
<?php echo Mage::getBlockSingleton('directory/data')->getCountryHtmlSelect($this->getEstimateCountryId()) ?>
</div>
</li>
<?php if($this->getStateActive()): ?>
<li>
<label for="region_id"<?php if ($this->isStateProvinceRequired()) echo ' class="required"' ?>><?php if ($this->isStateProvinceRequired()) echo '<em>*</em>' ?><?php echo $this->__('State/Province') ?></label>
<div class="input-box">
<select id="region_id" name="region_id" title="<?php echo $this->__('State/Province') ?>" style="display:none;"<?php echo ($this->isStateProvinceRequired() ? ' class="validate-select"' : '') ?>>
<option value=""><?php echo $this->__('Please select region, state or province') ?></option>
</select>
<script type="text/javascript">
//<![CDATA[
$('region_id').setAttribute('defaultValue', "<?php echo $this->getEstimateRegionId() ?>");
//]]>
</script>
<input type="text" id="region" name="region" value="<?php echo $this->escapeHtml($this->getEstimateRegion()) ?>" title="<?php echo $this->__('State/Province') ?>" class="input-text" style="display:none;" />
</div>
</li>
<?php endif; ?>
<?php if($this->getCityActive()): ?>
<li>
<label for="city"<?php if ($this->isCityRequired()) echo ' class="required"' ?>><?php if ($this->isCityRequired()) echo '<em>*</em>' ?><?php echo $this->__('City') ?></label>
<div class="input-box">
<input class="input-text<?php if ($this->isCityRequired()):?> required-entry<?php endif;?>" id="city" type="text" name="estimate_city" value="<?php echo $this->escapeHtml($this->getEstimateCity()) ?>" />
</div>
</li>
<?php endif; ?>
<li>
<div class="input-box">
<input class="input-text validate-postcode<?php if ($this->isZipCodeRequired()):?> required-entry<?php endif;?>" type="text" id="postcode" name="estimate_postcode" value="<?php echo $this->escapeHtml($this->getEstimatePostcode()) ?>" />
</div>
</li>
</ul>
<div class="buttons-set">
<button id="button-cep" style="width: 100px;" type="button" title="<?php echo $this->__('Get a Quote') ?>" onclick="calculaFreteAjax(jQuery('#postcode').val()); return false;" class="btn btn-2 btn-2a"><?php echo $this->__('Get a Quote') ?></button>
</div>
</form>
<script type="text/javascript">
//<![CDATA[
new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>);
//]]>
</script>
<?php $_shippingRateGroups = $this->getEstimateRates(); ?>
<?php if ($_shippingRateGroups): ?>
<form id="co-shipping-method-form" action="<?php echo $this->getUrl('checkout/cart/estimateUpdatePost') ?>">
<dl class="sp-methods">
<?php foreach ($_shippingRateGroups as $code => $_rates): ?>
<dt><?php echo $this->escapeHtml($this->getCarrierName($code)) ?></dt>
<dd>
<ul>
<?php foreach ($_rates as $_rate): ?>
<li<?php if ($_rate->getErrorMessage()) echo ' class="error-msg"';?>>
<?php if ($_rate->getErrorMessage()): ?>
<?php echo $this->escapeHtml($_rate->getErrorMessage()) ?>
<?php else: ?>
<input name="estimate_method" type="radio" value="<?php echo $this->escapeHtml($_rate->getCode()) ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio" />
<label for="s_method_<?php echo $_rate->getCode() ?>"><?php echo $this->escapeHtml($_rate->getMethodTitle()) ?>
<?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
<?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
<?php echo $_excl; ?>
<?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
(<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
<?php endif; ?>
</label>
<?php endif ?>
</li>
<?php endforeach; ?>
</ul>
</dd>
<?php endforeach; ?>
</dl>
</form>
<?php endif; ?>
<script type="text/javascript">
//<![CDATA[
var coShippingMethodForm = new VarienForm('shipping-zip-form');
var countriesWithOptionalZip = <?php echo $this->helper('directory')->getCountriesWithOptionalZip(true) ?>;
coShippingMethodForm.submit = function () {
var country = $F('country');
var optionalZip = false;
for (i=0; i < countriesWithOptionalZip.length; i++) {
if (countriesWithOptionalZip[i] == country) {
optionalZip = true;
}
}
if (optionalZip) {
$('postcode').removeClassName('required-entry');
}
else {
$('postcode').addClassName('required-entry');
}
return VarienForm.prototype.submit.bind(coShippingMethodForm)();
}
//]]>
</script>
</div>
</div>
<div class="col-xs-6">
<?php
$totalItemsInCart = Mage::helper('checkout/cart')->getItemsCount(); //total items in cart
$totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals(); //Total object
$subtotal = $totals["subtotal"]->getValue(); //Subtotal value
$grandtotal = $totals["grand_total"]->getValue(); //Grandtotal value
if(isset($totals['discount']) && $totals['discount']->getValue()) {
$discount = $totals['discount']->getValue(); //Discount value if applied
} else {
$discount = '';
}
$shipping = Mage::helper('checkout')->getQuote()->getShippingAddress()->getData();
$tax = $shipping["shipping_amount"];
/*if( $totals["tax"]->getValue()) {
$tax = $totals["tax"]->getValue(); //Tax value if present
} else {
$tax = '';
}*/
?>
<table class="totals-cart">
<tr>
<td class="total-tile">
Subtotal do pedido:
</td>
<td class="total-price">
<?php echo Mage::helper('core')->currency($subtotal, true, false); ?>
</td>
</tr>
<tr>
<td class="total-tile">
Frete:
</td>
<td class="total-price">
<?php echo Mage::helper('core')->currency($tax, true, false); ?>
</td>
</tr>
<?php if ($discount):?>
<tr>
<td class="total-tile">
Desconto:
</td>
<td class="total-price">
<?php echo Mage::helper('core')->currency($discount, true, false); ?>
</td>
</tr>
<?php endif;?>
</table>
</div>
</div>
<div class="row">
<div class="col-xs-16">
<div class="grand-total">
<p class="text">Total:</p>
<p class="price"><?php echo Mage::helper('core')->currency($grandtotal, true, false);?></p>
</div>
</div>
</div>
<script type="text/javascript">
function calculaFreteAjax(cep) {
jQuery('.contem-shipping .shipping').html('<span class="remove-frete" style="display: block; margin: 0 auto; width: 20px;" id="login-please-wait"><img src="http://sites.xpd.com.br/cpaps/skin/frontend/xpd/default/images/opc-ajax-loader.gif" class="v-middle" alt=""/></span>');
var param = {'country_id': 'BR','estimate_postcode': cep};
console.log(param);
jQuery.ajax({
type: "GET",
url: '<?php echo Mage::getBaseUrl().'checkout/cart/estimateAjaxPost/'; ?>', //My Custom Controller
data: param,
success: function(response) {
response = jQuery.parseJSON(response);
if(response.shipping) {
jQuery('.contem-shipping').parent().html(response.shipping);
}
else {
alert('Falha ao calcular o frete. Tente novamente.');
}
}
});
jQuery('#co-shipping-method-form dd input.radio').click(function(){
//I will submit the shipping method selected
});
}
</script>
Denis... I have modify code please check
public function estimateAjaxPostAction()
{
$country = (string) $this->getRequest()->getParam('country_id');
$postcode = (string) $this->getRequest()->getParam('estimate_postcode');
$city = (string) $this->getRequest()->getParam('estimate_city');
$regionId = (string) $this->getRequest()->getParam('region_id');
$region = (string) $this->getRequest()->getParam('region');
$this->_getQuote()->getShippingAddress()
->setCountryId($country)
->setCity($city)
->setPostcode($postcode)
->setRegionId($regionId)
->setRegion($region)
->setCollectShippingRates(true);
$this->_getQuote()->save();
$response = array();
$response['shipping']=$this->eastmatesajax();
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
}
protected function eastmatesajax()
{
$layout=$this->getLayout();
$layout->getMessagesBlock()->setMessages(Mage::getSingleton('checkout/session')->getMessages(true),Mage::getSingleton('catalog/session')->getMessages(true));
$block = $this->getLayout()->createBlock('checkout/cart_shipping')->setTemplate( 'checkout/cart/shipping.phtml');
return $block->toHtml();
}
Updated block issue solved using $this->_getQuote()->collectTotals(); before $this->_getQuote()->save();