DIV refresh with index - javascript

I ask for your help regarding the refreshment of my DIV.
When loading my page, _promo.php is called but does not update the data of this page.
Can you help me please ?
I don't know much about javascript
<?php include($_SERVER["DOCUMENT_ROOT"]."/includes/header.php"); ?>
<?php
try {
$stat = $pdo->query( "SELECT * FROM tab_shop_produits");
$i = 0;
while ($data = $stat->fetch( PDO::FETCH_ASSOC)) {
$reference = $data["reference"];
?>
<div id="promo_<?php echo $i; ?>" class="mb-2 text-end small text-success blink_"></div>
<input type="hidden" id="txt_reference_<?php echo $i; ?>" value="<?php echo $reference; ?>">
<?php
$i++;
}
} catch(PDOException $e){
echo "<div class='alert alert-danger'>".$e->getMessage()."</div>";
}
?>
<script>
$(document).ready(function(){
function loadLog(i) {
var reference = document.getElementById("txt_reference_" + i).value;
var intTotal = parseInt('<?php echo $i; ?>');
$.ajax({
type: "POST",
url: "_promo.php",
cache: true,
data: {reference: reference},
error: function (e) {console.log('Ajax Error', e);alert('Erreur Ajax');},
success: function(html){
document.getElementById("promo_"+i).innerHTML = html;
console.log(html);
i=parseInt(i)+1;
if(i<intTotal){setTimeout(loadLog(i), 1000);}
}
});
}
setTimeout(loadLog('<?php echo $i; ?>'), 1000);
});
</script>
<?php include($_SERVER["DOCUMENT_ROOT"]."/includes/footer.php"); ?>

Related

How to Upload multiple featured images in a custom post (Wordpress)

Actually my data is getting stored in backend but I'm not able to display it in frontend , also i want to add multiple images in post type wordpress plugin
You can follow the code:
//Add meta box in the post or page
add_action( 'add_meta_boxes', 'custom_postpage_meta_box' );
function custom_postpage_meta_box(){
$post_types = array('post');
foreach($post_types as $pt){
add_meta_box('custom_postpage_meta_box',__( 'More Featured Images', 'textdomain'),'custom_postpage_meta_box_func',$pt,'side','low');
}
}
//Load the field in meta screen
function custom_postpage_meta_box_func($post){
$meta_keys = array('second_featured_image');
foreach($meta_keys as $meta_key){
$image_meta_val=get_post_meta( $post->ID, $meta_key, true);
?>
<div class="custom_postpage_wrapper" id="<?php echo $meta_key; ?>_wrapper" style="margin-bottom:20px;">
<img onclick="custom_postpage_add_image('<?php echo $meta_key; ?>');" src="<?php%20echo%20(%24image_meta_val!=''?wp_get_attachment_image_src(%20%24image_meta_val)%5B0%5D:'');%20?>" style="width:100%;cursor:pointer;display: <?php echo ($image_meta_val!=''?'block':'none'); ?>" alt="">
<a class="addimage" style="cursor:pointer;" onclick="custom_postpage_add_image('<?php echo $meta_key; ?>');"><?php _e('Set featured image','textdomain'); ?></a><br>
<a class="removeimage" style="cursor:pointer;display: <?php echo ($image_meta_val!=''?'block':'none'); ?>" onclick="custom_postpage_remove_image('<?php echo $meta_key; ?>');"><?php _e('Remove featured image','textdomain'); ?></a>
<input type="hidden" name="<?php echo $meta_key; ?>" id="<?php echo $meta_key; ?>" value="<?php echo $image_meta_val; ?>">
</div>
<?php } ?> <script>function custom_postpage_add_image(key){
var $wrapper = jQuery('#'+key+'_wrapper');
custom_postimage_uploader = wp.media.frames.file_frame = wp.media({
title: '<?php _e('select image','textdomain'); ?>',
button: {
text: '<?php _e('select image','textdomain'); ?>'
},
multiple: false
});
custom_postpage_uploader.on('select', function() {
var attachment = custom_postpage_uploader.state().get('selection').first().toJSON();
var img_url = attachment['url'];
var img_id = attachment['id'];
$wrapper.find('input#'+key).val(img_id);
$wrapper.find('img').attr('src',img_url);
$wrapper.find('img').show();
$wrapper.find('a.removeimage').show();
});
custom_postpage_uploader.on('open', function(){
var selection = custom_postpage_uploader.state().get('selection');
var selected = $wrapper.find('input#'+key).val();
if(selected){
selection.add(wp.media.attachment(selected));
}
});
custom_postpage_uploader.open();
return false;
}
function custom_postpage_remove_image(key){
var $wrapper = jQuery('#'+key+'_wrapper');
$wrapper.find('input#'+key).val('');
$wrapper.find('img').hide();
$wrapper.find('a.removeimage').hide();
return false;
}</script> <?php wp_nonce_field( 'custom_postpage_meta_box', 'custom_postpage_meta_box_nonce' );
?>
}
//Save the meta box
add_action( 'save_post', 'custom_postimage_meta_box_save' );
function custom_postimage_meta_box_save($post_id){
if ( ! current_user_can( 'edit_posts', $post_id ) ){ return 'You have no permission to edit this post types'; }
if (isset( $_POST['custom_postimage_meta_box_nonce'] ) && wp_verify_nonce($_POST['custom_postimage_meta_box_nonce'],'custom_postimage_meta_box' )){
$meta_keys = array('second_featured_image');
foreach($meta_keys as $meta_key){
if(isset($_POST[$meta_key]) && intval($_POST[$meta_key])!=''){
update_post_meta( $post_id, $meta_key, intval($_POST[$meta_key]));
}else{
update_post_meta( $post_id, $meta_key, '');
}
}
}
}
For more details please read the article https://yourblogcoach.com/upload-multiple-featured-images-in-a-post-or-page/
Thank you

Codeigniter Jquery : I want reload this page same

I want when I add a product to the cart and reload the same page, but the problem did not this product.
The controller
public function detail()
{
$data=array('title' =>'Ecommerce Online | Detail Product',
'username' => $this->session->userdata('id'),
'categories' => $this->categories_model->get_categories(),
'details' => $this->categories_model->get_details($this->uri->segment(3)),
'isi' =>'member/detail');
$this->load->view('template_home/wrapper',$data);
}
function addtocart()
{
if($this->cart_model->validate_add_cart_item() == TRUE){
if($this->input->post('ajax') != '1'){
redirect('member/detail/'); // this problem
}else{
echo 'true';
}
}
}
I add my models
function validate_add_cart_item()
{
$id = $this->input->post('product_id');
$cty = $this->input->post('quantity');
$this->db->where('productID', $id);
$query = $this->db->get('product', 1);
if($query->num_rows > 0){
foreach ($query->result() as $row)
{
$data = array(
'id' => $id,
'qty' => $cty,
'price' => $row->price,
'name' => $row->productName
);
$this->cart->insert($data);
return TRUE;
}
}else{
return FALSE;
}
}
I add my view
<?php foreach ($details as $s) { ?>
<div class="col-md-5">
<div class="box text-center">
<img src="<?php echo base_url('upload/'.$s->photo); ?>" width="150px" height="150px">
<br><?php echo $s->productName; ?>
<br><strong>Rp. <?php echo $s->price; ?></strong>
<br>
<?php echo form_open('member/add'); ?>
<fieldset>
<label>Quantity</label>
<?php echo form_input('quantity', '1', 'maxlength="2"'); ?>
<?php echo form_hidden('product_id', $s->productID); ?>
<?php echo form_submit('add', 'Add'); ?>
</fieldset>
<?php echo form_close(); ?>
</div>
</div>
<?php } ?>
Jquery script
<script type="text/javascript">
$(document).ready(function() {
/*place jQuery actions here*/
var link = "<?php echo site_url('member/detail')?>/"; // Url to your application (including index.php/)
$(".detail-product").submit(function(){
var id = $(this).find('input[name=product_id]').val();
var qty = $(this).find('input[name=quantity]').val();
$.post(link + "member/add", { product_id: id, quantity: qty, ajax: '1' },
function(data){
if(data == 'true'){
$.get(link + "member/detail", function(cart){ // Get the contents of the url cart/show_cart
$("#cart_content").html(cart); // Replace the information in the div #cart_content with the retrieved data
});
}else{
alert("Product does not exist");
});
return false; // Stop the browser of loading the page defined
});
});
</script>
This is problem url: http://localhost/scientificwriting/member/detail/ and productid can not be invoked. Do I need to replace the IF statement on my controller and my jquery?
Please help me thanks

Jquery val() cannot read html tags received by php echo

this is my code, i have send value to input :
<script type="text/javascript">
Drupal.behaviors.devenirClientDepuisServiceform = {
attach: function (context, settings) {
jQuery(document).ready(function($) {
//$('.webform-component--nom-abnonnement>input').val('<?php echo $_GET['name']; ?>');
//$('.webform-component--produits-choisie>input').val('<?php echo $produitnid ?>');
jQuery('.webform-component--nom-abnonnement>input').val('<?php echo $produitname ?>');
jQuery('.webform-component--produits-choisie>input').val('<?php echo $produitnid ?>');
jQuery('.webform-component--type-de-client>input').val('<?php echo $type ?>');
jQuery('.webform-component--contrat>input').val('<?php echo $imageUrl; ?>');
});
}
};
//
</script>
$imageUrl is a text html
but jquery cannot understand and give me this error :
SyntaxError: unterminated string literal
try with using these quotes ` and removing line break of last one
jQuery(document).ready(function($) {
//$('.webform-component--nom-abnonnement>input').val('<?php echo $_GET['name']; ?>');
//$('.webform-component--produits-choisie>input').val('<?php echo $produitnid ?>');
jQuery('.webform-component--nom-abnonnement>input').val(`<?php echo $produitname ; ?>`);
jQuery('.webform-component--produits-choisie>input').val(`<?php echo $produitnid ; ?>`);
jQuery('.webform-component--type-de-client>input').val(`<?php echo $type ?>`);
jQuery('.webform-component--contrat>input').val(`<?php echo str_replace(array("\r", "\n"), '', $imageUrl); ?>`);
});
You forgot to write ";".. add ; after every echo statement
jQuery(document).ready(function($) {
//$('.webform-component--nom-abnonnement>input').val('<?php echo $_GET['name']; ?>');
//$('.webform-component--produits-choisie>input').val('<?php echo $produitnid; ?>');
jQuery('.webform-component--nom-abnonnement>input').val('<?php echo $produitname; ?>');
jQuery('.webform-component--produits-choisie>input').val('<?php echo $produitnid; ?>');
jQuery('.webform-component--type-de-client>input').val('<?php echo $type; ?>');
jQuery('.webform-component--contrat>input').val('<?php echo $imageUrl; ?>');
});

opencart Price range slider extension

Please help me to correct the code. Where it is conflicting with other javascript action. This price filter in opencart is stopping the action of Add to cart in category page. following is the code where php is called inside the javascript. Something is missing or not properly coded.
<div class="row">
<div class="slide-filter">
<h2><?php echo $heading_title; ?></h2>
<div class="list-group">
<div class="list-group-item">
<div id="filter-group1">
<div id="scale-slider"></div>
<button type="button" id="button-price-filter" class="filter-button"><?php echo $button_filter; ?></button>
</div>
</div>
</div>
</div>
</div>
and the javascript is
$("#scale-slider")
.slider({
min: <?php echo round($price_range_min) ; ?>,
max: <?php echo round($price_range_max) ; ?>,
range: true,
values: [<?php echo (isset($price_range[0])?$price_range[0]:0); ?>, <?php echo (isset($price_range[1])?$price_range[1]:$price_range_max); ?>]
})
.slider("pips", {
rest: false,
<?php if (!$right_code) { ?>
prefix: "<?php echo $price_code; ?>",
<?php } else { ?>
suffix: "<?php echo $price_code; ?>"
<?php } ?>
})
.slider("float");
(function( $ ) {
$(function() {
$('#button-price-filter').on('click', function() {
priceRange = [];
$('#scale-slider .ui-slider-tip').each(function(){
priceRange.push($(this).html());
});
$('.<?php echo $product_class; ?>').hide();
$('.clearfix').remove();
$('.<?php echo $product_class; ?>').each(function(){
if( $(this).find( ".price span.price-new" ).length ) {
var price = $(this).find( ".price span.price-new" ).html().replace('<?php echo $price_code; ?>','').replace(',','');
} else {
var text = $(this).find('.price').html().replace('<?php echo $price_code; ?>','');
if( $(this).find( ".price span" ).length ) {
var price = text.substring(0,text.indexOf('<span')).replace(',','');
} else {
var price = text.replace(',','');
}
}
price = parseInt(price);
if( !isNaN(price) && (price > priceRange[0] && price < priceRange[1]) ){
$(this).fadeIn("slow");
}
});
});
});
})(jQuery);
remove the $('.clearfix').remove(); ,may be work perfectly

To store value of textbox in session

Here, If I write name of textbox is id from an array, then how it would be use in session.?
Updated:
My code is:
foreach($abc as $row)
{
<input type="text" name="<?php echo $row['id']; ?>" class="txt" id=txt_"<?php echo $row['id']; ?>" onblur="doAjax(this)"/>
}
Javascript code:
$(document).on('blur','.txt',function(){
$.ajax({
type: "GET",
url: "view_orders_checked_array.php",
data: {task: 'alltxt'},
async: false
});
});
In view_orders_checked_array.php:
if($task == "alltxt")
{
$_SESSION["textareaID"] = [];
foreach($rows as $row)
{
$al[] = array_push($_SESSION["textareaIDs"], $row["id"]);
}
print_r($al);
}
So, how it would possible to store textbox value in session array.?
Start the session at the top of every page that you want to access the session:
<?php session_start();
Then to add data to the session array:
<?php $_SESSION["foo"] = $bar; ?>
So if your textarea ID is $row["id"], you can do:
<?php $_SESSION["textareaID"] = $row["id"]; ?>
then call it whenever you want by doing:
<?php echo $_SESSION["textareaID"]; ?>
Of course, you can name the session array variable anything you want.
Or in a foreach loop:
<?php
$_SESSION["textareaIDs"] = [];
foreach($rows as $row){
array_push($_SESSION["textareaIDs"], $row["id"]);
} ?>

Categories

Resources