/    Sign up×
Community /Pin to ProfileBookmark

(jQuery Sortable) My ajax callback causes items not to display, NO idea why.

Not sure whether or not this is a syntax problem with my function or an error in my ajax syntax but no matter how I try re-writing this ‘receive’ callback it always causes my lists to display empty.

Example of the first function (There are 10 or so of these)

What it’s supposed to do:

If a sortable receives any item from another list (Receive: callback)

The variable boxnum represents the list that has received the new item.
The variable id represents the element that has been moved.

We send both values to a php script so that we can change ‘BOXID’ in the db to ‘boxnum’ (the new box the element has been moved to) using ID for the WHERE part of the query.

All in all: Next time user refreshes the page the element will be in the box the user moved the item to last time! Persisting state!

[CODE]function getList()
{
$.ajax({
url: “list.php”,
success: function(feedback){
if(feedback != “”)
{
$(‘#myList’).html(feedback);
$(‘#myList’).sortable({
connectWith: $(‘.biglist’),
placeholder: ‘help’,
revert: true,
cursor: ‘move’,
axis: ‘vertically’,
opacity: 0.4,
containment: ‘parent’,
update : function (sorted) {
serial = $(‘#myList’).sortable(‘serialize’);
$.ajax({
url: “sort.php”,
type: “POST”,
data: serial,
success: function(feedback)
{
$(‘#data’).html(feedback);
}
});
}
receive : function (sorted) [COLOR=”Red”]//problem might be here[/COLOR]
{
boxnum = $(this).attr(‘boxnum’);
id = $(this).find(‘div:first’).attr(‘refnum’);
$.ajax({
url: “boxsort.php”,
type: “POST”,
data: {‘boxnum’: boxnum, ‘id’: id},
success: function(feedback) [COLOR=”red”]//problem might also be here, not sure[/COLOR]
{
$(‘#data’).html(feedback); [COLOR=”red”]//might even be here![/COLOR]
}
});
}
});
$(‘#myList’).sortable(“refresh”);

}
}
});
}[/CODE]

I don’t think there’s anything wrong with the php script, since we haven’t even gotten a chance to call it yet since we don’t have any items displaying to drag around but here it is for reference (Just incase!)

[code=php]
<?php

$currentID = $_POST[‘id’];
$boxNew = $_POST[‘boxnum’];

include(“config.php”);

mysql_query(“UPDATE `Itemscopy` SET `boxid` = “.$boxNew.” WHERE `itemid` = “.$currentID.””);

mysql_close($cfg[‘connexion’]);
?>[/code]

Thanks so much ?

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @Sodascript spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...