Delay scroll down - scroll

How to delay the scroll down for few seconds?
My Code:
<script type="text/javascript">
$(function(){
$("#tmp_image-37113").click (function() {
$('#section--41340').show(150);
$('html, body').animate ({
scrollTop: $("#section--41340").offset().top
}, 2000);
return false;
});
});
</script>

Related

How ajax working on wame server?

Hi all I am first time starting to learn ajax from website w3schools, and I follow the step by step I'm trying to get an AJAX example working but i'm unable to get it working. could you help me please ? thanks you.
And here is my code
ajax.php
<!DOCTYPE html>
<html>
<body>
<div id="demo"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadDoc()">Change Content</button>
<script>
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
document.getElementById("demo").innerHTML = xhttp.responseText;
}
};
xhttp.open("GET", "ajax_info.txt", true);
xhttp.send();
}
</script>
</body>
</html>
You can use ajax like this,
<script>
function loadDoc() {
$.ajax({
xhr: function() {
var xhr = new window.XMLHttpRequest();
//progress
xhr.upload.addEventListener("progress", function(e) {
//progress value e
load_progress(e);
}, false);
return xhr;
},
type: "GET",
url: "ajax_info.txt",
success: function(msg) {
//when success //200 ok
document.getElementById("demo").innerHTML = msg;
},
error: function(jqXHR, textStatus, errorThrown) {
//when error
}
});
}
</script>

How to handle mouseout event on DC range graph

I am using DC chart range filter. I want to handle mouse out event on range filter, so I can handle filter on mouse-out. I had used filter and post-redraw but when I use this there are multiple time event fire on single drag on range chart. I need only the last change event and I think a mouse out or mouse up event would be helpful. Can any one help me with how to use mouse up/mouse out event on range Chart?
chart.on('postRender', function() {
chart.select('.brush').on("mouseover", function() {
console.log('mouseover');
});
chart.select('.brush').on("mouseout", function() {
console.log('mouseout');
});
chart.select('.brush').on("mouseup", function() {
console.log('mouseup')
});
chart.select('.brush').on("click", function() {
console.log('click')
});
});
Working snippet below:
var data = [{
date: "2011-11-21",
total: 90
}, {
date: "2011-11-22",
total: 90
}, {
date: "2011-11-23",
total: 90
}, {
date: "2011-11-24",
total: 200
}, {
date: "2011-11-25",
total: 200
}];
var cf = crossfilter(data);
var timeDimension = cf.dimension(function(d) {
return new Date(d.date);
});
var totalGroup = timeDimension.group().reduceSum(function(d) {
return d.total;
});
var chart = dc.lineChart("#chart")
.width(400)
.height(200)
.x(d3.time.scale().domain(d3.extent(data, function(d) {
return new Date(d.date);
})))
.dimension(timeDimension)
.group(totalGroup)
.renderArea(true)
.brushOn(true);
chart.xAxis().ticks(4);
function caught(eventName) {
document.getElementById(eventName).className = 'bold';
setTimeout(function() {
document.getElementById(eventName).className = '';
}, 750);
}
chart.on('postRender', function() {
chart.select('.brush').on("mouseover", function() {
console.log('mouseover');
caught('mouseover');
});
chart.select('.brush').on("mouseout", function() {
console.log('mouseout');
caught('mouseout');
});
chart.select('.brush').on("mouseup", function() {
console.log('mouseup')
caught('mouseup');;
});
chart.select('.brush').on("click", function() {
console.log('click')
caught('click');;
});
});
chart.render();
<link href="https://cdnjs.cloudflare.com/ajax/libs/dc/1.7.3/dc.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.2.0/d3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crossfilter/1.3.11/crossfilter.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dc/1.7.3/dc.js"></script>
<style>
.bold {
font-weight: bold;
}
</style>
<div id="chart"></div>
<div id="mouseout">mouseout</div>
<div id="mouseover">mouseover</div>
<div id="mouseup">mouseup</div>
<div id="click">click</div>

Redrawing Google Pie Chart with AJAX

I am using the following pie chart code that is being fed data from a query:
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Customers', 'Status'],
['Accepted', <?php echo $rowsaccepted ;?>],
['Declined', <?php echo $rowsdeclined;?>],
['Not Reviewed', <?php echo $rowsnreview;?>]
]);
var options = {
'width':200,
'height':200,
'backgroundColor':'#474747',
'legend': 'none',
'chartArea':{left:20,top:0,width:250,height:250},
colors: ['#ef8200', '#007fc2', '#41cf0f'],
fontSize:14,
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
</script>
and the following AJAX call that updates my DB upon clicking a button; therefore updating the chart data, but I must refresh the page for the chart to refresh:
<script type="text/javascript">
$(function() {
$(".decline").click(function(){
var element = $(this);
var del_id = element.attr("id1");
var order_id = element.attr("data-order1");
$.ajax({
type: "POST",
url: "decline.php",
data: {id1:del_id,order_id1:order_id},
success: function(){cache: false}
});
$(this).parents(".show").animate({ backgroundColor: "#003" }, "slow")
.animate({ opacity: "hide" }, "slow");
});
});
</script>
Is there any way I can add a call in my AJAX function that will refresh and redraw the pie chart without requiring the page to be refreshed?
Thanks!

Load data in a popup using Ajax

I'm using magnificient popup on my website, and I would like to execute ajax function when a link is clicked and the result of the query should be the content od the popup.
this is my code (I'm pretty new in JQuery) :
<script>
function showPics(str)
{
if (str=="")
{
document.getElementById("displayPics").innerHTML="";
return;
}
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("displayPics").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getpics.php?q="+str,true);
xmlhttp.send();
}
</script>
<a class="1-popup" href="#">Guerlain</a>
<script type="text/javascript">
$('a').click(function() {
showPics($(this).attr('class').charAt(0)), //Ajax function call
$(this).magnificPopup({ //Popup call
type:'inline',
midClick: true,
closeBtnInside:true
});
});
</script>
<div id="displayPics"><b>Pictures will be listed here.</b></div>
The content is loaded, but the popup not.
Here's the solution of my issue :
<a class="1-popup" href="#displayPics">Guerlain</a>
<script type="text/javascript">
$('a').click(function(){
showPics($(this).attr('class').charAt(0)) //Ajax function call
});
</script>
<script type="text/javascript">
$('a').magnificPopup({ //Popup call
type:'inline',
midClick: true,
closeBtnInside:true
});
</script>
<div id="displayPics" class="white-popup mfp-hide"><b>Pictures will be listed here.</b></div>
Thank you all.

$.ajax serialize() does not pass data to php file

What is incorrect in the code? Can not pass data to _autosave.php
<script type="text/javascript">
$(document).ready(function(){
autosave();
});
function autosave() {
var t = setTimeout("autosave()", 5000);
var inputValues= $('.input_form').serialize();
$.ajax( {
type: "POST",
url: "_autosave.php",
data: inputValues,
} )
.done(function(data){
alert(data);
});
...
    
Input is this
<form id="input_form" autocomplete="off" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]) ?>"
method="post">
<input type="text" name="input" id="input">
_autosave.php is this
$input = $_POST['input'];
echo $input .' input<br>';
If I enter some value in input, get input<br> instead of entered value
Update
If for someone may be necessary here is working code
$.post("_autosave.php", $("#form1").serialize(), function(data) {
$('#load').html(data);
$('#is_row_changed1').val(0)
});
You have a trailing comma here resulting in invalid javascript:
data: inputValues,
Here's how you could fix (and improve your current code):
<script type="text/javascript">
$(document).ready(autosave);
function autosave() {
window.setTimeout(autosave, 5000);
var inputValues = $('.input_form').serialize();
$.ajax({
type: "POST",
url: "_autosave.php",
data: inputValues
})
.done(function(data) {
alert(data);
});
}
</script>
or if you prefer a shorthand:
<script type="text/javascript">
$(document).ready(autosave);
function autosave() {
window.setTimeout(autosave, 5000);
var inputValues = $('.input_form').serialize();
$.post("_autosave.php", inputValues, function(data) {
alert(data);
});
}
</script>
Have you tried with serializeArray() instead?
<script type="text/javascript">
$(document).ready(autosave);
function autosave() {
window.setTimeout(autosave, 5000);
$.post("_autosave.php", $('.input_form').serializeArray(),
function(data) {
alert(data);
});
}
</script>

Resources