php - $.post not working when element dropped -
i'm teaching myself jquery , php , i'm having few problems. need element id posted php script once dropped on droppable div. following code not post when drag , drop element on droppable div. have tried following:
- i have removed apart alert box check item has been dropped does, item being seen droppable!.
- i have entered content div manually ensure results can been seen
- i have replaced name var name="test", test varible contents.
the javascript file , php script reside in same directory, file names correct. javascript drag , drop script included after droppable area
<script type="text/javascript" src="js/drag-drop.js"></script>
i have replaced result of php script plain text see if problem variable received, nothing returns. post not seem getting php script. hope can provide few pointers!
below code, html div.
$(document).ready(function() { $('#carousel-ul li').draggable({ helper: 'clone', revert: true }); $('#drop').droppable({ hoverclass: 'drophover', accept: '#carousel-ul li', drop: function(){ //alert("has been accepted , dropped"); var name = ui.helper.attr('id').val(); $.post('javascript.php', { name: name }, function(data){ $('#drop-content').html(data); }); } }); }); <?php //echo "id posted"; if(isset($_post['name'])){ $name = $_post['name']; var_dump($name); echo name; //echo "id posted inside"; } ?>
the api documentation droppable widget says ui
parameter jquery object, should try this:
$('#drop').droppable({ hoverclass: 'drophover', accept: '#carousel-ul li', drop: function(event, ui) { var name = $(ui.helper).attr('id'); var content = $(ui.helper).html(); $.post('javascript.php', { name: name, content: content }, function(data) { $('#drop-content').html(data); }); } });
Comments
Post a Comment