我正在尝试在“index.php”中使用拖放功能并将变量“元素”发布到“store.php”,在最终版本中它应该更新数据库。
'store.php' 被调用并运行,但变量没有被传递。我在下面附上了一个缩短版本的“store.php”,并带有一个陷阱来捕捉这个,所以在这个版本中,我得到了“未设置元素值”的响应。
索引.PHP:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script src="scripts/jquery-1.3.2.min.js"></script>
<script src="scripts/jquery-ui-1.7.1.custom.min.js"></script>
<link rel="stylesheet" href="style.css">
<div class="content_box" id="content_box_drag" onMouseOver="drag();">
Drag label
<?php for($i=0; $i<5;$i++) {
echo "<p class='dragelement' id='dragelement_$i'>Ferrari_$i</p>";
} ?>
</div>
<div class="content_holder_box" id="content_box_drop">
Drop here
<p class="dropper"></p>
</div>
<div style="clear:both;"></div>
<br/><br/>
<div id="search_result"></div>
<script>
//initialize the drag and drop functions.
function drag(){
$( "#content_box_drag p" ).draggable({
appendTo: "body",
helper: "clone",
revert: "invalid"
});
$( "#content_box_drop p" ).droppable({
activeClass: "dropper_hover",
hoverClass: "dropper_hover",
accept: ":not(.ui-sortable-helper)",
drop: function( event, ui ) {
var ele = ui.draggable.text();
$.ajax({
url: "store.php",
method: "POST",
data: "element=" + ele,
success: function(result) {
alert(result);
}
});
}
});
}
</script>
STORE.PHP(缩短):
<?php
if(isset($_POST['element'])){
$element=$_POST['element'];
} else {
echo "Element value not set";
exit;
}
?>
任何想法为什么没有设置变量?