I have a jquery php mysql query, which works fine, but before my form being submitted, I would like to tell my visitors how many results will they receive. For example: Show results (5).
Could you tell me an easy way of doing that please?
I would really appreciate it.
edit: my ajax looks like the following:
<script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
}catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
}catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data
// sent from the server and will update
// div section in the same page.
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('ajaxDiv');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
// Now get the value from user and pass it to
// server script.
var bedno = document.getElementById('bedno').value;
var district = document.getElementById('district').value;
var loc = document.getElementById('location').value;
var queryString = "?bedno=" + bedno ;
queryString += "&district=" + district + "&location=" + loc;
ajaxRequest.open("GET", "ajax-example.php" +
queryString, true);
ajaxRequest.send(null);
}
//-->
</script>
Your AJAX is right.
In your ajax-example.php file fetch the result using your parameters.
And echo the result.
example
$st = mysqli_query($link, "your query");
$result = mysqli_num_rows($st);
echo $result;
Related
I want to resume uploading after the internet is connected again
if the internet is cutoff for short time it resumes again but if the time increased ,it wouldn't increase the progress of uploading
my Script :
document.forms["upload-vimeo"].onsubmit = function(e){
e.preventDefault();
let file = this.url.files[0];
let id= "' . $id . '";
let type= this.video_type.value;
let name= this.name.value;
let description= this.description.value;
let formdata = new FormData();
formdata.append("url", file);
formdata.append("id", id);
formdata.append("type", type);
formdata.append("name", name);
formdata.append("description", description);
let http = new XMLHttpRequest();
http.upload.addEventListener("progress", function(event){
let percent = (event.loaded / event.total) * 100;
document.querySelector("progress").value = Math.round(percent);
var element = document.getElementById("value");
element.innerHTML = Math.round(percent)+" %";
});
http.addEventListener("load", function(){
if(this.readyState == 4 && this.status == 200){
if(!this.responseText){
console.log(this.responseText);
window.location.replace("' . $url . '");
}
else{
console.log(this.responseText);
}
}
});
http.open("post", "script.php");
http.send(formdata);
}
My php is normal uploading to vimeo
any ideas to reach that ?
I have this script tag in my page and it is successfully downloading as html to canvas. I want to save this generated html2canvas in phpMyAdmin.
This is my code added-
<script type="text/javascript">
function downloadimage() {
//var container = document.getElementById("image-wrap"); //specific element on page
var container = document.getElementById("htmltoimage");; // full page
html2canvas(container, { allowTaint: true }).then(function (canvas) {
var link = document.createElement("a");
document.body.appendChild(link);
link.download = "html_image.jpg";
link.href = canvas.toDataURL();
link.target = '_blank';
link.click();
});
}
//var container = document.getElementById("image-wrap"); //specific element on page
var container = document.body; // full page
html2canvas(container).then(function(canvas) {
var link = document.createElement("a");
document.body.appendChild(link);
link.download = "invoice.png";
link.href = canvas.toDataURL("image/png");
link.target = '_blank';
link.click();
});
var container = document.getElementById("htmltoimage");; // full page
html2canvas(container,{allowTaint : true}).then(function(canvas) {
var link = document.createElement("a");
document.body.appendChild(link);
link.download = "invoice.png";
link.href = canvas.toDataURL("image/png");
link.target = '_blank';
link.click();
});
</script>
I am trying to build a mobile application using cordova. I needed a qr-scanner so I added the phonegap barcode scanner for this purpose:
https://github.com/phonegap/phonegap-plugin-barcodescanner
The script i am trying to run is the following:
<script>
function scan() {
cordova.plugins.barcodeScanner.scan(
function (result) {
var xmlhttp;
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
cadeaubon = JSON.parse(xmlhttp.responseText);
}
}
xmlhttp.open("GET", "php/getCadeaubon.php?id=" + result.text, true);
xmlhttp.send();
},
function (error) {
alert("Scanning failed: " + error);
},
{
preferFrontCamera : false, // iOS and Android
showFlipCameraButton : true, // iOS and Android
showTorchButton : true, // iOS and Android
torchOn: false, // Android, launch with the torch switched on (if available)
saveHistory: true, // Android, save scan history (default false)
prompt : "Place a barcode inside the scan area", // Android
resultDisplayDuration: 500, // Android, display scanned text for X ms. 0 suppresses it entirely, default 1500
formats : "QR_CODE,PDF_417", // default: all but PDF_417 and RSS_EXPANDED
orientation : "landscape", // Android only (portrait|landscape), default unset so it rotates with the device
disableAnimations : true, // iOS
disableSuccessBeep: false // iOS and Android
}
);
}
</script>
The php script that runs with this XMLHttpRequest is the following:
<?php
$id = $_GET['id'];
$server = "127.0.0.1";
$username = "root";
$password = "AHR1822";
$db = "lekker_lokaal";
$conn = new PDO("mysql:host=$server;dbname=$db", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$result = $conn->query("
SELECT cadeaubonID, handelaarsID, genBonLocatie, waarde, ontvanger, koper, aankoopdatum, status
FROM cadeaubons
WHERE cadeaubonID ='".$id."'
");
$outp = array();
$outp = $result->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($outp);
?>
But when I run the android or browser build of this project, instead of runne-ing the php code, it just returns the file.
This worked fine when I used this same method in a normal web application.
Can someone help me, because I am out of ideas right now.
I am having problems uploading a file with CordovaFileTransfer plugin in ionic.
I have sound file that has been recorded and i need help uploading it.
var targetPath = e.nativeURL;
var win = function (r) {
console.log("Code = " + r.responseCode);
console.log("Sent = " + r.bytesSent);
}
var fail = function (error) {
alert("An error has occurred: Code = " + error.code);
console.log("upload error source " + error.source);
console.log("upload error target " + error.target);
}
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=filename;
options.mimeType="audio/wav";
var params = new Object();
params.value1 = "test";
params.value2 = "param";
options.params = params;
options.chunkedMode = false;
var ft = new FileTransfer();
ft.upload(targetPath, "http://example.come/upload.php", win, fail, options);
And my php script looks like this
header('Access-Control-Allow-Origin: *');
print_r($_FILES);
$new_image_name = "audio.wav";
move_uploaded_file($_FILES["file"]["tmp_name"], "/var/www/html/snappycast_uploads/files/".$new_image_name);
Have any idea what I am doing wrong??
I'm trying to draw points onto a map based on data in a Postgres DB, can anyone tell me why this won't work.. I'm scratching my head trying to figure it out.
I'm pulling data from a Postgres DB using this PHP code, which appears to be working just fine:
<?php
ini_set('memory_limit', '1024M');
// Connecting, selecting database
$dbconn = pg_connect(**MY LOGON DEETS**)
or die('Could not connect: ' . pg_last_error());
$lat1 = $_GET['lat1'];
$lat2 = $_GET['lat2'];
$lng1 = $_GET['lng1'];
$lng2 = $_GET['lng2'];
$pin_points = 'SELECT lat,lng,price,address_string FROM house_price_data_db.main where lat>=$1 and lat<=$2 and lng<=$3 and lng>=$4';
$result_pinpoints_points = pg_query_params($dbconn,$pin_points,array($lat1,$lat2,$lng1,$lng2)) or die('Query failed: ' . pg_last_error());
$pin_points_array = array();
while($r = pg_fetch_assoc($result_pinpoints_points)) {
$pin_points_array[] = $r;
}
header("Content-type: application/json" ); // set the header to json
echo(json_encode(array_values($pin_points_array), JSON_NUMERIC_CHECK)); // this will return json
pg_close($dbconn);
?>
To try and draw points on a map, using the code outlined below. I feel there's an error/issue with my Javascript, but I can't figure it out:
var lat1=55.55;
var lat2=56.05;
var lng1=8.00;
var lng2=8.45;
function setMarkers(){
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var pinpoints = JSON.parse(xmlhttp.responseText);
var marker;
var i=0;
var lat;
var lng;
var price;
var address;
var post_latlng;
var content;
for (i = 0;i<pinpoints.length;i++){
a=pinpoints[i];
lat=parseFloat(a["lat"]);
lng=parseFloat(a["lng"]);
price=parseFloat(a["price"]);
address=String(a["address_string"]);
post_latlng = new google.maps.LatLng(lat,lng);
content = "<b>Price:</b> " + price + '</br>' + "<b>Address:</b> " + address;
var marker = new google.maps.Marker({
map: map,
title: address,
position: post_latlng
});
map.setCenter(marker.getPosition());
var infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(marker,'click', (function(marker,content,infowindow){
return function(){
infowindow.setContent(content);
infowindow.open(map,marker);
};
})(marker,content,infowindow));
}
}
}
xmlhttp.open("GET","pinpoints.php?lat1="+lat1+"&lat2="+lat2+"&lng1="+lng1+"&lng2="+lng2,false);
xmlhttp.send();
}
For some reason it won't work, I expect the function to call the PHP script, return an array and then use this array's contents and the Javscript function to draw markers on a map, that when clicked display some information. When I use Firebug I'm not getting any errors. Any suggestions on how to resolve this are more than welcome.
It turns out my code was working ok, but that the query I was sending to the database to test the function didn't have any returned rows.