I have a web application that is using Drag/Drag capabilities for sorting data. I have discovered that on IOS devices drag and drop via safari is a no go. I'm looking for a temporary solution to allow the application to run while I work on an IOS app. I'm wondering if it is possible to use Ajax to POST on click to a dataworker page I have that processes the drag and drop actions. Here is what I have so far.
Page1.php contains
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="/js/script.js"></script>
<header class="main-header" role="banner"><center>
</header>
</head>
<body>
<center>
<table>
<tr><td>
<div id="available" ondrop="drop('list', event)" ondragover="allowDrop(event)">
<p> <font color="blue">SID</font> | Last, First </p> <?php
include "database_connection.php";
///////////////////////////////////////////////////////////////////////////////////////////////
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s
", mysqli_connect_error());
exit();
}
else
{
}
$query = "*******";
if ($result = mysqli_query($link, $query)) {
/* fetch associative array */
while ($row = mysqli_fetch_assoc($result)) {
echo "<p id='{$row["sID"]}' draggable='true' onclick='drop(event)' ondragstart='dragStart(event)' width='75' height='75'> <font color='blue'> {$row["sID"]}</font> | {$row["lastName"]}, {$row["firstName"]}</p></a>";
}
/* free result set */
mysqli_free_result($result);
}
mysqli_close($link);
/////////////////////////////////////////////////////////////////////////////////
?>
</div>
</td>
<td>
<div id="order" ondrop="drop('order', event)" ondragover="allowDrop(event)">
<?php
include "database_connection.php";
///////////////////////////////////////////////////////////////////////////////////////////////
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s
", mysqli_connect_error());
exit();
}
else
{
}
$query = "*********";
if ($result = mysqli_query($link, $query)) {
/* fetch associative array */
while ($row = mysqli_fetch_assoc($result)) {
echo "<p id='{$row["sID"]}' draggable='true' ondragstart='dragStart(event)' width='75' height='75'><font color='blue'> {$row["sID"]} </font>| {$row["lastName"]}, {$row["firstName"]} </p></a>";
}
/* free result set */
mysqli_free_result($result);
}
mysqli_close($link);
/////////////////////////////////////////////////////////////////////////////////
?>
</div>
</td>
</tr>
</body>
</html>
Script.js contains
function drop(containerId, e) {
var id = event.dataTransfer.getData("id");
console.log(id);
$.ajax({
url: "dataworker.php",
type: "POST",
data: {
id: id,
containerid: containerId,
//fileName: file.name, // Your file name.
//file: event.target.result // Your file.
},
success: function() {
console.log('great success');
window.location.reload()
return true
}
});
}
function dragStart(e) {
console.log(e);
e.dataTransfer.setData("id", e.srcElement.id);
}
function allowDrop(e) {
e.preventDefault();
}
And the third page, Dataworker, simply accepts the POSTS via php and processes them. Is it possible to also have an Onclick perform the same action as drop? My hope is that can be done, and I wont have to use traditional hard coded get ahrefs to accomplish my goal. it is important to note that since they are also drag and drop if I use the same functions as the drag and drop I need to account for the containerID. That way the POST feature knows that it is actually going to the opposite container, and not the one it was clicked in.