我有几个div id,每个都包含一个不同的客户端。我希望能够单击删除按钮并使用ajax和jquery从数据库中删除特定的div。我在AJAX中取得了成功,但它并没有从数据库中删除任何内容。显然,删除后,我希望容器能够动态重新加载。帮助!
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.
有什么想法吗?
答案 0 :(得分:2)
dataToLoad = 'clientID=' + clientID + '&deleteclient=yes',
您的控制器的clientID值为0。
跟踪您的clientID javascript变量,看看它是否正在获取正确的clientID。