我有幾個div id,每個id都包含不同的客戶端。我希望能夠點擊刪除按鈕,並使用Ajax和jQuery從數據庫中刪除特定的div。我在AJAX中取得了成功,但它並未從數據庫中刪除任何內容。顯然,刪除後,我想容器重新加載動態。幫幫我!!!使用ajax和jquery刪除div id並從數據庫中刪除
function DeleteClient(){ clientID = $('.clientblock').attr('id') alert(clientID); var yes = confirm("Whoa there chief! Do you really want to DELETE this client?"); if (yes == 1) { dataToLoad = 'clientID=' + clientID + '&deleteclient=yes', $.ajax({ type: 'post', url: '/clients/controller.php', datatype: 'html', data: dataToLoad, success: function(html) { alert('Client' + clientID + ' should have been deleted from the database.'); $('#clientscontainer').html(html); }, error: function() { alert('error'); }});}; }; controller.php info // Variables necessary are: $deleteClient $clientID on the delete click, when being passed through post (via firebug) clientID = 0 deleteClient = yes
編輯:所以很明顯,它沒有得到正確的客戶端ID將其刪除的數據庫,因爲它是通過職位,但我得到一個AJAX的成功呼叫,在那裏我有客戶端ID變量顯示那裏,它正在挑選正確的客戶端ID。
alert(clientID) is pulling in 0 as well.
任何想法?
你必須在這裏放一些關於你的controller.php的信息。 嘗試使用Firebug來跟蹤發佈到控制器的帖子,看看發生了什麼 - 參數等。 – ronaldosantana 2010-04-12 22:45:29