I have a store locator, built using Google Maps, PHP/Mysql and jQuery here:
http://tinyurl.com/4w8nwwp
Everything is dandy in FF, Safari,Chrome and Opera.
IE7, 8 cannot read the XML that is dynamically generated by parse_location.php
The AJAX code:
function reloadMap(map, dataString) {
markersArray = [];
var infoWindow = new google.maps.InfoWindow({content: "loading...", maxWidth:100});
var storeListHtml = '<h2>Name <span style="margin-left:252px;">Address</span></h2><ul>';
$.ajax({
type: "GET",
url: "parse_location.php",
data: dataString,
success: function(text){
count = -1;
$(text).find("list").each(function()
{
count++;
if(count == 0)
{
var burnsvilleMN = new google.maps.LatLng($(this).attr("lat"),$(this).attr("lng"));
map.panTo(burnsvilleMN);
}
var store = [$(this).attr("name"), $(this).attr("address"), $(this).attr("lat"), $(this).attr("lng"), count];
var name = $(this).attr("name");
var address = $(this).attr("address");
var point = new google.maps.LatLng($(this).attr("lat"),$(this).attr("lng"));
var html = "<span class='info'><b>" + name + "</b> <br/>" + address + "</span>";
var image = new google.maps.MarkerImage('images/icon_dot2.png');
var shadow = new google.maps.MarkerImage('images/icon_dot_shadow.png');
var marker = new google.maps.Marker({
map: map,
position: point,
icon: image,
shadow:shadow
//shadow: icon.shadow
});
//markersArray.push(marker);
storeListHtml += "<li class='store'><a href='javascript:myclick("+count+")'><div class='store-name'>"+name+"</div><div class='store-add'> "+address+"</div></a></li>";
bindInfoWindow(marker, map, infoWindow, html);
});
storeListHtml += '</ul>';
$("#store-list").html(storeListHtml);
}
});
}
As you can see, this involves calling parse_location.php, getting the XML generated by this code:
// uncommenting the following line causes ff, safari et al to not show anything.
// header('Content-Type: text/xml; charset=UTF-8');
$responce = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$responce .= "<location>\n";
$city = $_GET['city'];
$category = $_GET['category'];
[SQL Query here ]
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$responce .= "<list name=\"".$row["name"]."\"
address=\"".$row["street_address"]." ".$row["city"]." ".$row["state"].", ".$row["zip"]."\"
lat=\"".$row["lat"]."\"
lng=\"".$row["lng"]."\" />";
}
$responce .= "</location>";
$responce8 = utf8_encode($responce);
echo $responce8;
Any pointers???
Rishi
Add a Content-Type header to your php code like this:
header('Content-Type: text/xml'); // Try "application/xml" too
Also, adding another IE-specific header might help:
header('X-Content-Type-Options: nosniff');
You need to do this before outputting anything else of course, since they are headers.
Related
How can I send my converted exif coordinates (in decimals) to my db using php and mysql? I'm using one file for this (addnew.php)
I'm sending information through a form in php like:
if(isset($_POST['btn_submit'])){
$username = $_POST['userName'];
$watervisibility = $_POST ['waterVisibility'];
$divinglocation = $_POST['divingLocation'];
$imgFile = $_FILES['user_art']['name'];
$tmp_dir = $_FILES['user_art']['tmp_name'];
$imgSize = $_FILES['user_art']['size'];
I also use libraries to convert exif to decimals ( on change ) to avoid clicking submit. This is all still in the same php file (addnew.php) (this is where i'm having a problem)
var lat;
var latref;
var long;
var longref;
var dec;
var myLatLng;
document.getElementById("input-group").onchange = function(e) {
EXIF.getData(e.target.files[0], function() {
//console.log(EXIF.pretty(this));
long = EXIF.getTag(this, 'GPSLongitude');
longref = EXIF.getTag(this, 'GPSLongitudeRef');
lat = EXIF.getTag(this, 'GPSLatitude');
latref = EXIF.getTag(this, 'GPSLatitudeRef');
dec = dms2dec(long, longref, lat, latref);
console.log("Decimal 1: " + dec[0] + " Decimal 2: " + dec[1]);
console.log("Longref: " + longref);
console.log("Latref: " + latref);
console.log("Long Length: " + long.length);
console.log("Longtitude: " + long);
console.log("Latitude: " + lat);
myLatLng = {lat: dec[1], lng: dec[0]}
myLat = {lat: dec[1]}
myLng = {lng: dec[0]}
console.log(myLat);
console.log(myLng);
});
}
Now I got the decimals and basically just want to send
myLat = {lat: dec[1]}
myLng = {lng: dec[0]}
to my db through php at the same time i'm submitting everything else.
I've tried Send JSON data from Javascript to PHP but I can't seem to get the hang of it
Any ideas?
Thanks!
To send javascript obj to php using json and ajax:
js:
var dataPost = {
"var": "foo"
};
var dataString = JSON.stringify(dataPost);
$.ajax({
url: 'server.php',
data: {myData: dataString},
type: 'POST',
success: function(response) {
alert(response);
}
});
to use that object in php:
$obj = json_decode($_POST["myData"]);
echo $obj->var;
In fact we generate from an HTML file administrative documents for each customer.
On the other hand this pdf generated will be saved to a specific folder on the server to be sent to the customer concerned.
Can I serve the backup path by doc.save order?
My code:
function createpdf() {
var canvasToImage = function(canvas){
var img = new Image();
var dataURL = canvas.toDataURL('image/png');
img.src = dataURL;
return img;
};
var a4 =[595.28,2000];
var canvasShiftImage = function(oldCanvas,shiftAmt){
shiftAmt = parseInt(shiftAmt) || 0;
if(!shiftAmt){ return oldCanvas; }
var newCanvas = document.createElement('canvas');
newCanvas.height = oldCanvas.height - shiftAmt;
newCanvas.width = oldCanvas.width;
var ctx = newCanvas.getContext('2d');
var img = canvasToImage(oldCanvas);
ctx.drawImage(img,0, shiftAmt, img.width, img.height, 0, 0, img.width, img.height);
return newCanvas;
};
var canvasToImageSuccess = function(canvas){
var pdf = new jsPDF('p','px','letter'),
pdfInternals = pdf.internal,
pdfPageSize = pdfInternals.pageSize,
pdfScaleFactor = pdfInternals.scaleFactor,
pdfPageWidth = pdfPageSize.width,
pdfPageHeight = pdfPageSize.height,
totalPdfHeight = 0,
htmlPageHeight = canvas.height,
htmlScaleFactor = canvas.width / (pdfPageWidth * pdfScaleFactor),
safetyNet = 0;
while(totalPdfHeight < htmlPageHeight && safetyNet < 15){
var newCanvas = canvasShiftImage(canvas, totalPdfHeight);
pdf.addImage(newCanvas, 'png',0, 0, pdfPageWidth, 0, null, 'NONE');
totalPdfHeight += (pdfPageHeight * pdfScaleFactor * htmlScaleFactor );
if(totalPdfHeight < htmlPageHeight){
pdf.addPage();
}
safetyNet++;
}
pdf.save('<?php echo $mavariable?>.pdf');
};
html2canvas($('main')[0], {
onrendered: function(canvas){
canvasToImageSuccess(canvas);
}
});
}
I guess you want to send the PDF in the mail attachment. For from client side code make a request to server with the generated PDF's (by jsPDF) base64 string format.
var pdfData = pdf.output();
You can post PDF data (base64) to server there again you have convert base64 string to PDF then save it to any temporary path if you want. Thereby you can mail it the PDF.
https://stackoverflow.com/a/35684594/2090459
I have been trying a dozen ways to save a dataurl generated from an svg to my server. This code seems like it should be working based on other threads I've read here but for some reason it just creates a .png file with 0kb. I went ahead and just copy/pasted the dataurl right into my script to avoid any data being sent to php issues right now, I just want to see the php create the image correctly. Here's my code:
$img="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAiYAAAGQCAYAAACatauzAAAgAElEQVR4Xuy9C5Bd1XkuuPY5p1+ipW61QOiBUSMhB0dcJGI8uTUxVy1V2amZugO4Mjck4IzEVPCYZKYQju+ti2OwYrA9Vbk2eG4lUGqqJBkJhkx5eNzM1MSuWC2TVDnXsvUA2TJCUguQEBJqdevZj3POnv/f56zuv0+fx36svfdaa/+rSjRSr73W2t+/9t7f+p+O4MYIMAKMACPACDACjIAmCDiarIOXwQgwAowAI8AIMAKMgGBiwpuAEWAEGAFGgBFgBLRBgImJNqLghTACjAAjwAgwAowAE5OE98DA9u29or34KAB/YM+DD7+e8PQ8HSPACDACjAAjoDUCTEwSFM/A7m3rcsIZcoXoqU476gjnNVe4rzFJSVAQPBUjwAgwAoyAtggwMUlQNBt2De4Ar55Ndy+8QVwrlcRbV8bciVLJkwH8Z0wId0/Zzb0m8lN7h/74keEEl8ZTMQKMACPACDACWiDAxCRBMUhicv+SFeKunj5v5rcvj4nDl0bFsWuXxYWpSbqaA64jhhzUpjzwpb0JLpOnYgQYAUaAEWAEUkOAiUmC0A+8/Fy/Uy6c6GtrF4+vXDNn5tMT18Sxq5c8snL86uXp37M2JUEh8VSMACPACDACqSKQSWKycfe2V13H6XVdMSRyxZ1Jmk3qaU3q7YBr5RKQlMuNtCngm+IOlYVzwHHcIdaopPoM8eSMACPACDACChHIHDGRWguJIWojysIdGHrwSwei4jrw0gv3Cddd6zhiABxcD+RcID/C3Vwdd9Qtiy+IQnG4mdak0RqkNgXJCv5/jdkHL6uYfoBsuZOFvUMPPTQa9X74ekaAEWAEGAFGIG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EO2iQBQQ0OJkSTfmNIlh4n2ZzpMy+vb5XskomJjjuS1xQZAQwfzrUXt8BT/BgYaxfgw/KHEJqaRXttZDAVDsA5TBSCmeBQVG5cbyoZ4KmTuJwRE3m1wWHrOiggWFs9vVHo/fPvH/VMcdjw+g64fnlHl4OhyfhexFxPzUxD1Cem9s7xOsiy7VVcbopKDZnCAyOQLVhDfZMUE5Nk9hjPkhICXn6TtuKz8ERuwiUgMcFTuu022pTgbjntjlPHvagEbGwSaAmXNh1M+1BoA1yEhSDx2DPykdh3ccSdKpe9D/9NULn9f1p2y7T/HPb5LkS5YYI3jG7DRJKYMkH619X6dEmtRu2ykKBgdWR6rexDn9l6tyMLHOKctWRJ9scaQ/+6Z5FXjVk+/zjn5yBkul52XNP2G2d+jbDRs3wpZosF886zgIHnf4IP4T2Ll7P/ScKbgqqnMbSbCWLCAgg5nWm1S0LepraXoTmk8t6am4yQykbeAPpwYEp8TNwmtSWo6fo5/B2JQSOCgtfjM/kZeD+iqebYtcvi9bMfeBoRJBD43sSGBOTnF897Vdtv7pon/vvrl3uHPlwL1imjrTbzdq0mqDbhHF77/2+0YTJok+Kow2gRAg7L5gQw/v8PaqCA15/YCYqB15+MnqVBi9DGNBN6SNcPoAzH6FZh+oQ5NWwZare9UsPPQ8kM0OLkg8DRlQffv2J1NrbTekENlrvfPhNsqMAMpFZHArRWBTQKA2rUIAPItBIveGHsU+CZL7vfvgBLD4VyYnTEZCjllkHsVtD2YuAiskbY+hNcQ4qD2AtDzmmgAgl0ERwQ/AEO+7KAenCjYGiEAKxhQqtdHUMjFAa/K0EjGaDRhktfP/7/BV33AYqzBGklvMcnwE6rBY3MYBtNocXFjaDGFOh6Cvj0D45FvaMNk8Gf7kZdOBoCoyEwGgKjITAaAqMhMIhCAAC+P4HZvnVG3QAAAABJRU5ErkJggg==";
$filedata = substr($img, strpos($img,",")+1);
file_put_contents("testfile2.png", base64_decode($filedata));
echo "file created";
Here's the jquery code that's generating the data. I just copy it from the alert to test in this script:
$("#testclick").click(function() {
var svg = document.getElementById("map").innerHTML; // or whatever you call it
//alert(svg);
$('#load-target').html(svg);
var canvas = $('#load-target svg')[0];
try {
svgAsDataUri(canvas, null, function(uri) {
var image = new Image();
image.src = uri;
image.onload = function() {
var canvas = document.createElement('canvas');
canvas.width = image.width;
canvas.height = image.height;
var context = canvas.getContext('2d');
context.drawImage(image, 0, 0);
var a = document.createElement('a');
a.download = name;
alert(canvas.toDataURL('image/png'));
a.href = canvas.toDataURL('image/png');
document.body.appendChild(a);
a.click();
}
//alert(uri);
$.post("http://www.srqnews.com/maps/create.php",
{
type:"PNG",
datauri:uri
},
function(data,status){
alert("Data: " + data + "\nStatus: " + status);
});
});
} catch(err) {
alert(err.message);
}
});
how to send data from javascript to php?if i use ajax, there will be error?
here's my code
script.js
function uploadPhoto(imageURI) {
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
options.chunkedMode = false;
var ft = new FileTransfer();
ft.upload(imageURI, "http://*my_ip*/TA/php/upload.php", win, fail, options);
};
upload.php
include 'db.php';
$t=time();
$id_place = $_GET["id_place"];
$file_name = $_FILES["file"]["name"].$t.".jpg";
$dir_full = "images/full/"."full_".$file_name;
$dir_small = "images/small/"."small_".$file_name;
move_uploaded_file($_FILES["file"]["tmp_name"], $dir_full);
$im_src = imagecreatefromjpeg($dir_full);
$src_width = imageSX($im_src);
$src_height = imageSY($im_src);
$dst_width = 50;
$dst_height = ($dst_width/$src_width)*$src_height;
$im = imagecreatetruecolor($dst_width,$dst_height);
imagecopyresampled($im, $im_src, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
imagejpeg($im, $dir_small);
$temp = "http://*my_ip*/TA/php/images/full/"."full_".$file_name;
$temp2 = "http://*my_ip*/TA/php/images/small/"."small_".$file_name;
//$id_place = .$id_place;
$query = "insert into gallery values ('','$id_place','$temp','$temp2')";
mysql_query($query);
imagedestroy($im_src);
imagedestroy($im);
if i use ajax, the script.js will be like this (correct me if im wrong)
script.js with ajax
function uploadPhoto(imageURI) {
jquery.ajax({
type: 'GET',
url: 'http://203.189.122.77/TA/php/gallery.php',
data: {id_place: window.localStorage("id_place")},
dataType: 'jsonp',
jsonp: 'jsoncallback',
timeout: 5000,
success: function(data, status){
//alert(window.localStorage.getItem("id_place"));
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
options.chunkedMode = false;
var ft = new FileTransfer();
ft.upload(imageURI, "http://203.189.122.77/TA/php/upload.php", win, fail, options, true);
},
error: function(){
alert('There was an error when download images');
}
});
};
if i use ajax, there always be in error function.if im not use ajax, i cannot get id_place
With JSONP, the server does not return a regular JSON object, rather it returns a JavaScript function to be run on the client. Your client code then executes the function returned from the server for access to the data.
I believe another post: Simple jQuery, PHP and JSONP example?
will explain how to do this in your context.
To understand the mechanics of JSONP more generally, http://en.wikipedia.org/wiki/JSONP might be of use.
Hi I'm wanting to post a variable from ajax js file to a php file. here is my attempt so far.
var request = createRequest();
var deletenode = node.id;
window.alert("nodeid=" + deletenode);
var vars = "deletenode="+deletenode;
request.open("POST", "deletenode.php", true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.onreadystatechange = function() {
handleRequest(request);
};
request.send("deletenode=" + encodeURIComponent(deletenode));
here is my php file
<?php
print_r($_POST);
$node = $_POST['deletenode'];
print "node to be deleted: $node";
?>
nothing comes up in my php file, what can be the issue. my ajax request is intact and working right too. thank you and here is my handle request.
function handleRequest(request) {
// we only care for now about when we get to readyState 4
// which means the request completed and we have the response back
if(request.readyState == 4){
//alert("response: " + request.responseText); // check to see what
// we got back just for testing
// now get response's TEXT and put into document (specify where)
// below we have an html element with the id as timeLoc
json= eval ("(" + request.responseText + ")");;
//alert ("json="+json); //tests what was recieved
//clicking the close button
closeButton.onclick = function() {
node.setData('alpha', 0, 'end');
node.eachAdjacency(function(adj) {
adj.setData('alpha', 0, 'end');
var request = createRequest();
var deletenode = node.id;
window.alert("nodeid=" + deletenode);
var vars = "deletenode="+deletenode;
request.open("POST", "deletenode.php", true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.onreadystatechange = function() {
handleRequest(request);
};
request.send("deletenode=" + encodeURIComponent(deletenode));
});
}// end readystate=4
}//end handle request
Remember you have to send the data as key/value pairs - request.send("deletenode=" + encodeURIComponent(deletenode));
I'm not sure if this is a copy/paste error, but if that's your actual code you appear to be missing a few curly braces closes. And have a double;; at the end of your eval line. This is the code tidied up with the extra curly braces, does that work?
function handleRequest(request) {
if(request.readyState == 4){
json= eval ("(" + request.responseText + ")");
closeButton.onclick = function() {
node.setData('alpha', 0, 'end');
node.eachAdjacency(function(adj) {
adj.setData('alpha', 0, 'end');
var request = createRequest();
var deletenode = node.id;
window.alert("nodeid=" + deletenode);
var vars = "deletenode="+deletenode;
request.open("POST", "deletenode.php", true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.onreadystatechange = function() {
handleRequest(request);
};
request.send("deletenode=" + encodeURIComponent(deletenode));
});
}
}
}