【发布时间】:2011-09-04 10:29:33
【问题描述】:
使用 jquery ui 可排序,当发生更改时,将执行函数“位置”。它有一个 ajax 帖子,但在触发位置时不会发送:
$('#col').Sortable(
{
accept: 'widget',
opacity: 0.5,
helperclass: 'helper',
change: positions,
handle: '.widget_title_bar'
}
);
但是,“位置”确实有效,因为当我通过 onclick 操作正常调用它时,会发送 ajax 帖子。我唯一能想到的是职位是用javascript而不是jquery编写的。我该如何解决这个问题?
编辑我已包括以下职位:
function positions(){
var widgets = '';
var column = document.getElementById('col');
for(i = 0; i < col_1.childNodes.length; i++) {
var str1 = col_1.childNodes[i].className;
if(str1 && str1.match('widget')) widgets+='&c[1]['+i+']='+col_1.childNodes[i].id;
}
xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
xmlhttp.open('POST', '/positions.php', true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("widgetpositions="+widgets);
xmlhttp.send(null);
return true;
}
【问题讨论】:
-
嗨 Dr.Molle,我已将“职位”功能编辑到我上面的原始帖子中。谢谢。
-
函数里面的col_1是什么?
-
抱歉,col_1 应该是 col。我编辑了一些代码以缩短 stackoverflow 的代码,但忘记更改了。
-
如果您使用 jQuery UI,您必须使用 jQuery,然后您可能应该使用 jquery 中的一种 ajax 方法来让您的生活更轻松。
标签: jquery ajax jquery-ui jquery-ui-sortable