This is my Javascript
$(document).ready(function(){
$( ".ex" ).draggable({containment:'parent',cursor:'pointer',opacity:0.6,
stop : function () {
var x = $(this).position().left;
var y = $(this).position().top;
$.ajax({
url: "savedrag.php", /* You need to enter the URL of your server side script*/
type: "POST",
/* add the other variables here or serialize the entire form.
Image data must be URI encoded */
data:{
x: x,
y: y
},
success: function(msg)
{
alert("position save");
}
})
}
});
});
this is my PHP
<?php
$qry = "SELECT * from contact Where CustomerID='$pid'";
$result = mysql_query($qry);
while ($row = mysql_fetch_array($result))
{
echo '<div class="ex">';
$row["ContactID"];
echo '</div>';
}
?>
How can I pass in variable $row["ContactID"] into each function, so that each draggable div have their own indivdual position in the database?
Previvously I pass in value through button using onclick(this); but I cannot do the same for draggable.
With the given markup, you can
$(document).ready(function() {
$(".ex").draggable({
containment : 'parent',
cursor : 'pointer',
opacity : 0.6,
stop : function() {
var x = $(this).position().left;
var y = $(this).position().top;
$.ajax({
url : "savedrag.php",
type : "POST",
data : {
x : x,
y : y,
ContactID: $.trim($(this).html())
},
success : function(msg) {
alert("position save");
}
})
}
});
});
You mean something like this:
Javascript addition:
var id = $(this).attr("id");
//...
data:{
x: x,
y: y,
id: id
}
php :
echo '<div class="ex" id="$row["ContactID"];">';
echo '</div>';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.