2011-05-29 56 views
1

使用jquery ui可排序,當發生變化時,執行函數'位置'。它裏面有一個ajax的文章,但位置被觸發時,它不會發送:Ajax調用不與jQuery UI使用

$('#col').Sortable(
        { 
         accept: 'widget', 
         opacity: 0.5, 
         helperclass: 'helper', 
         change: positions, 
         handle: '.widget_title_bar' 
        } 
       ); 

然而,「位置」絕對可行的,因爲當我通常把它通過一個onclick動作阿賈克斯後被髮送。我唯一能想到的是位置是用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; 
} 
+0

請向我們展示職位。 – 2011-05-29 20:28:36

+0

嗨Dr.Molle,我已經在'職位'功能編輯到我原來​​的職位上面。謝謝。 – james 2011-05-29 20:39:38

+0

函數裏面的col_1是什麼? – 2011-05-29 21:51:49

回答

1

的JavaScript標識符是大小寫敏感的,沒有.Sortable()功能jQuery用戶界面,使用.sortable()代替。

$('#col').sortable({ 
    accept: 'widget', 
    opacity: 0.5, 
    helperclass: 'helper', 
    change: positions, 
    handle: '.widget_title_bar' 
}); 
0

假設可排序的大寫S在縮短代碼時是一個錯字,這對我很有用。
誤差必須在其他地方,看到了演示:http://jsfiddle.net/doktormolle/xB8Wh/
(我只更換了「更新」,「改變」,但它與「太改」工程)

唯一的區別,從變化的呼叫 - (或任何其他可排序事件)將成爲範圍。
所以如果你使用某個函數內部的 -keyword,這將是#col如果函數是由排序事件調用,而從的onclick事件(指定內嵌)調用它會全局窗口對象。

那麼你用什麼地方這個裏面的函數?