$('.delete-section').live("click",function()
{
var ID = $(this).attr("id");
var dataStringDeleteSection = 'section_id='+ ID;
if(confirm("Are you sure you want to delete this Section? There is NO undo!"))
{
$.ajax({
type: "POST",
url: "/path/to/delete.php",
data: dataStringDeleteSection,
cache: false,
success: function(html){
doRefresh_showSections();
}
});
In one page i have put various actions (show/hide/add/delete).
One "show" action will present a table.
Table is enclosed in <div id="sections"></div>
In each row i have a delete link.
Pressing the delete will remove that row and reload the table.
First delete action works perfectly (first time i click delete link). If i delete again no jquery/action is performed. Instead i return to my original page (like a refresh/F5).
I have checked my data in show.php and the names of classes/divs are correct.
What do i do wrong?
Can you give us a URL of a live version? The code you provided seems to be OK ... maybe someone else has a clue? I think the problem might be somewhere else.
Please post at least the HTML part ... and please use code tags to present the code with the appropriate indentations. You can use the "#" button above the message box to fill in the code tags for you.
Ok, so i replace my table with css/div/spans and jquery works perfectly.
All the data that are now in <div id="registered-sections"></div> were in a table (2 colums, nothing fancy).
The current project code is as follows (sorry for length)
The jquery part is:
Code:
<script type="text/javascript">
$(document).ready(function () {
// after various ajax calls, show/hide content
function doRefresh_afterAjax()
{
window.location.replace("somepage.php");
}
// various show hide options
// by default, on page load we hide these DIVs
$("#sectionHolder").hide();
$("#view-main").hide();
// click actions
$(".section-manage").click(function () {
$("#tableHolder").hide();
$("#sectionHolder").show();
$("#view-main").show();
return false;
});
// click actions
$(".view-main").click(function () {
$("#tableHolder").show();
$("#sectionHolder").hide();
$("#view-main").hide();
return false;
});
$(".keyword-manage").click(function () {
$("#tableHolder").hide();
$("#sectionHolder").hide();
return false;
});
$(".edit-keyword").click(function () {
$("#tableHolder").hide();
$("#sectionHolder").hide();
return false;
});
$(".cancel").click(function () {
doRefresh_afterAjax();
return false;
});
//
// SECTIONS
//
function doRefresh_showSections()
{
$.ajax({
type: "POST",
url: "show.php",
data: "",
cache: false,
success: function(html){
$("div#registered-sections").html(html);
}
});
}
// ADD
$('.save-section').live("click",function()
{
var dataStringAddSection = $("form#addSection").serialize();
$.ajax({
type: "POST",
url: "add.php",
data: dataStringAddSection,
cache: false,
success: function(html){
if (html=='') { doRefresh_showSections(); } else { $("div#resultAjaxLoader").html(html); }
}
});
return false;
});
// DELETE
$('.delete-section').live("click",function()
{
var ID = $(this).attr("id");
var dataStringDeleteSection = 'section_id='+ ID;
if(confirm("Are you sure you want to delete this Frontend Section? There is NO undo!"))
{
$.ajax({
type: "POST",
url: "delete.php",
data: dataStringDeleteSection,
cache: false,
success: function(html){
doRefresh_showSections();
}
});
}
return false;
});
});
</script>