This is my code:
$(function(){
var btnUpload=$('#browse');
var adinfoid=$('#adinfoid').val();
new AjaxUpload(btnUpload, {
action: '<?php echo base_url()?>index.php/post/upload_editmainimage/'+adinfoid,
name: 'uploadfile',
onSubmit: function(file, ext){
$("#progressid").css("display","block");
if (! (ext && /^(jpg|png|jpeg|gif|JPG|PNG|JPEG|GIF)$/.test(ext))){
$("#mainphotoerror").html('Only JPG, PNG, GIF, files are allowed');
$("#mainphotoerror").css('display','block');
return false;
}
},
onComplete: function(file, response){ //alert(response);
if(response){
/*$(".main_image").html('');
$(".main_image").html(response);*/
$("#progressid").css("display","none");
$("#image"+<?php echo $mainimage->intphotoid; ?>).css('display','block');
$("#imagemainicon"+<?php echo $mainimage->intphotoid; ?>).css('display','block');
$("#mainimageicon").attr("src",response);
$("#mainimageicon").attr("width",55);
$("#mainimageicon").attr("height",55);
$("#mainimageicon1").attr("src",response);
}else{
alert("error");
}
}
});
});
<input type="button" id="browse" class="browse_media" value="Browse">
<div id="progressid" class="displayNone">
<img src="//s3.amazonaws.com/s3.racingjunk.com/102/images/procesing.gif" width="117" height="20" />
Uploading.....
</div>
When I click on the browse button I need to show a progress bar for 5 minutes. After 5 minutes the progress bar will hide or not be shown. After the progress bar hides the image will then display.
How can I do this? Is this possible?
Try this
http://www.9lessons.info/2012/04/file-upload-progress-bar-with-jquery.html
i haven't tried it myself but this night work
You have to do like this:--
<div id="popup1" class="popup_block">
<?php echo $this->Html->image('ajax-loader2.gif'); ?>
<h4>Processing Please Wait...! </h4>
</div>
In script:-
Using Jquery
//Fade in Background
jQuery('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
jQuery('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer
var popID = 'popup1';
//var popWidth = 500;
//Fade in the Popup and add close button
jQuery('#' + popID).css({ 'width': '250' });
for time you can give in Your Jquery or do like this:--
window.setInterval(function() {
// this will execute every 5 minutes => show the alert here
}, 300000);
You cannot achieve that using the code you have shared. You see, you need to know how much data has been sent to the server so that you can show actual progress.
How People do it?
1. They used third party plugins like java Applet or Flash to upload files
2. They use an animated picture to show progress while the file is being sent (not actual progress).
3. They use HTML 5.
For real time feedback on how much file has been sent to the server you will need either 3rd party plugin (if you are on an older browser) or HTML5 XMLHttpRequest Object
See html5 file upload with upload status/Progress bar.
Related
i am displaying a gif image on my wordpress site - when i refresh the page the gif is being cached at the final frame. I would like to make it so everytime the page is refreshed the gif restarts from the beginning. is their any code (php) i could add to the functions.php file in order for this to take place.
Thanks.
Tried a few different options on stack overflow such as:
<img id="gif" src=""/>
<script>document.getElementById('gif').src="path_to_picture.gif?a="+Math.random()</script>
and
var src = 'http://i.imgur.com/JfkmXjG.gif';
$(document).ready(function(){
var $img = $('img');
$('#target').toggle(
function(){
var timeout = 0; // no delay
$img.show();
setTimeout(function() {
$img.attr('src', src);
}, timeout);
},
function(){
$img.hide();
}
);
});
I have following script which fetch data from server based on form parameters.
jQuery('#request_search').submit(function(e){
e.preventDefault();
var s_date=jQuery('#actualfrom').val();
var e_date=jQuery('#actualto').val();
var type=jQuery("#type").val();
var loc=jQuery("#loc").val();
jQuery.post("scripts/get_gamma_activity_type.php", {"loc":loc,"start_date":s_date, "end_date":e_date, "type":type}, function(data) {
jQuery('#report').html(data);});
});
});
This part is working and some times, based on search criteria , it takes a couple of seconds to get results. in the mean time I would like to show some GIF saying data loading. I have the GIF ready. How to implement it in the above script?
please try this.
jQuery('#request_search').submit(function(e){
$("#report").html("<div><img src='loading.gif' alt='Loading.. \n Please wait' title='Loading.. \n Please wait'` /></div>");
e.preventDefault();
var s_date=jQuery('#actualfrom').val();
var e_date=jQuery('#actualto').val();
var type=jQuery("#type").val();
var loc=jQuery("#loc").val();
jQuery.post("scripts/get_gamma_activity_type.php", {"loc":loc,"start_date":s_date, "end_date":e_date, "type":type}, function(data) {
jQuery('#report').html(data);});
});
});
Add Image with path in your html file with id attribute and then show/hide div
based on request and success.
Try below code:
Add html div in your html file :
<div id='loadingmessage' style='display:none'>
<img src='loadinggraphic.gif'/>
</div>
Try below code of jQuery:
jQuery('#request_search').submit(function(e){
$('#loadingmessage').show(); // show the loading message.
e.preventDefault();
var s_date=jQuery('#actualfrom').val();
var e_date=jQuery('#actualto').val();
var type=jQuery("#type").val();
var loc=jQuery("#loc").val();
jQuery.post("scripts/get_gamma_activity_type.php", {"loc":loc,"start_date":s_date, "end_date":e_date, "type":type}, function(data) {
jQuery('#report').html(data);});
$('#loadingmessage').hide(); // hide the loading message
});
});
My jquery UI script works good. My #dialog has a couple of PHP sql Queries which fetches results. In this case after clicking the #open i want to use Ajax reguest. For example: I click the #open, after clicking UI dialog opens and inside dialog loads user_settings.php, while loading, it shows: Please wait, loading....
After a few seconds, it loads user_settings.php. I think the way which i have used, can load my index.php heavy.
$(document).ready(function(){
$("#dialog").load('ajax_dialog/user_settings.php')
.dialog({
autoOpen: false,
show: 'fade',
position: 'center center',
resizable:false,
draggable:false,
modal:true
});
$("#open").click(
function () {
$("#dialog").dialog('open');
return false;
}
);
});
</script>
HTML
<a id ="open" href="#">Open jquery UI DIALOG</a>
<div id="dialog" Title="My Jquery UI dialog"></div>
As Alex told you, is a bit confusing your question, but I think I understood what you want to do (I hope!).
HTML
<a id ="open" href="#">Open jquery UI DIALOG</a>
<div id="dialog" Title="My Jquery UI dialog">Please wait, loading...</div>
JS
$(document).ready(function(){
$("#open").click(function(){
$.ajax({
type: "POST",
url: "ajax_dialog/user_settings.php",
dataType: 'html',
success: function(data){
$('#dialog').html(data);
}
});
});
});
When you click on open, your dialog will display a "Please wait, loading..." message. After a few seconds, your dialog content will be replaced with your user_settings.php content.
If you don't echo nothing on your user_settings.php file, just replace the line $('#dialog').html(data); with your desire content.
Happy coding!
I did an ajax upload with php.Everything wiil be perfect in firefox.
But when i test it in chrome browser its not working correctly.
That means it displays this :
This is my ajax upload code:
$(function(){
var cntUp = 0;
var btnUpload=$('#upload0');
var status=$('#status');
var state='left_front';
new AjaxUpload(btnUpload, {
action: 'upload-file.php',
data: {saleid: $("#hid_saleid").val(),imag_state:state,custom:$('#custom').val()},
name: 'uploadfile',
onSubmit: function(file, ext){
if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){
// extension is not allowed
alert('Only JPG, PNG or GIF files are allowed');
return false;
}
this.setData({
'saleid': $("#hid_saleid").val(),
'imag_state':'left_front',
'custom':$('#custom').val()
});
status.text('Uploading...');
},
onComplete: function(file, response){
var array_data=response.split('***');
var fname= array_data[1];
var rand=Math.floor((Math.random()*10)+1);
var saleid = $("#hid_saleid").val();
var custom = $('#custom').val();
//On completion clear the status
status.text('image uploaded');
cntUp++;
//console.log(cntUp);
//Add uploaded file to list
if (response.toLowerCase().indexOf("success") >= 0 ) {
var image='<img src="uploads/'+saleid+'/'+fname+'" alt="" width="131px" height="125px"/>';
$("#img0").html(image);
} else{
$('<li></li>').appendTo('#files').text(file).addClass('error');
//alert('error');
}
}
});
});
This is the html code:
<div class="brwse_box">
<div style="float:left;" id="upload0">
<h3>Left Front</h3>
<img src="images/upload.gif" />
</div>
<div style="float:right; width:131; height:125" id="img0">
<?php if($l_ft==''||$l_ft==NULL) { ?>
<img src="images/no-photo-lft-frnt.jpg" id="bg"/>
<?php } if($l_ft!=''||$l_ft!=NULL){?>
<img src="uploads/<?php echo $var_sid;?>/<?php echo $l_ft;?>" id="bg" width="131px" height="125px"/>
<?php }?>
</div>
</div><!--browse_box ENDS-->
How can i solve this?
It displaying image in firefox.but in chrome not displaying image instead of that displaying html of image tag.
EDIT:
This is the value return in fname variable:
left_front.jpg<div id=isChromeWebToolbarDiv" style="display:none"></div>
It seems you have a problem in the src string.
Check it for escape characters...
I'd say it's possible that fname contains quotes...
EDIT:
What "isChromeWebToolbarDiv"?
fname = fname.replace(new RegExp("<div id=isChromeWebToolbarDiv(.*)</div>"),'');
or simply
fname = fname.replace(new RegExp("<div(.*)</div>"),'');
after your EDIT on question, it came to know that
is coming in src
This is caused by a Chrome extension called DVDvideosoftTB. It appears to append the above HTML to file upload requests. You can easily disable it:
Click on the Wrench icon
Click "Tools"
Click "Extensions"
Disable DVDvideosoftTB
I am using jQuery and PHP to save content that the user inputs in a database. While the PHP is doing its thing I want to show a loading GIF image just to show that it is saving their data. I realize that it probably does take that long for it to run the code so i want to be able to show the image for at least 1 second if it takes less time than that
For example, I'm using the following script as a live search form in a database.
The user types some letters and the script search if a student with that name exists in the database:
file index.php
<head>
//call to jquery.js
<script type='text/javascript'>
$(document).ready( function() {
$('#q').keyup( function(){
$field = $(this);
$('#results').html('');
$('#ajax-loader_e').remove();
if( $field.val().length > 1 )
{
var str='q='+$(this).val();
$.ajax({
type : 'GET',
url : 'ajax_search.php' ,
data : str ,
beforeSend : function() {
$field.after('<img src="../img/ajax-loader.gif" alt="loader" id="ajax-loader_e" />');
},
success : function(data){
$('#ajax-loader_e').remove();
$('#results').html(data);
}
});//end ajax
}//end if
});//end keyup
});//end ready
</script>
</head>
<body>
<form class="quick_search">
<input type="text" value="Name" id="q" name="q" onfocus="if(!this._haschanged){this.value=''};this._haschanged=true;">
</form>
<div id="results_e"></div>
file ajax_search.php
if(isset($_GET['q'])){
$nom='%'.safe($_GET['q']).'%';
$req=$connexion->prepare("SELECT * FROM students WHERE name LIKE :name LIMIT 0,10 ");
$req->execute(array('name'=>$name));
echo "<ul>";
while($row=$req->fetch(PDO::FETCH_ASSOC)){
if(empty($row)){
echo "<h4 class='alert_error'>No one with that name!</h4>";
}
else{
echo "<li><strong><a href='?id=".$row['id']."'>".clean($row['nom']).' '.clean($row['prenom'])."</a></strong></li>";
}
}
echo "</ul>";
}
You can use that script to save a form via ajax and display a loader gif while waiting.
The important parts are:
remove the loader in the beginning
in beforeSend, display the loader
remove the loader in success