javascript - Cancel button not behaving correctly with jQuery load event -
i have cancel button not working correctly.
when hit it, cancels, reloads page.
i thought adding "preventdefault" fix, did not.
here background:
on page called playerdata.aspx, displays character stats in element:
<div id="maingametext">
.
that data loaded via page "charactergeneratordisplay.aspx"
i have block of jquery code in "playerdata.aspx" controls character display/edit area supposed following:
when page loads, displays character data.
when user clicks area(), editor loads.
here block of jquery:
<script> $(document).ready(function () { //initial load character read-only $("#maingametext").load("../character/charactergeneratordisplay.aspx?charid=<%= session("currentcharid") %>"); //load character editor on div click $("#maingametext").click(function (e) { e.preventdefault(); $("#ajaxnodetext").load('../character/charactergeneratoredit.aspx?charid=<%= session("currentcharid") %>'); }); return false; }); </script>
the above script working. loads needed data , loads editor when area clicked.
in charactergeneratoredit.aspx page, have "save" , "cancel" button.
the "save" button .net control because backend .net , database stuff when saving character.
and closewindow() function reloads read-only page:
function closeeditor() {
$("#maingametext").load("../character/charactergeneratordisplay.aspx?charid=<%= session("currentcharid") %>");
}
the problem is, when hit cancel, load "charactergeneratordisplay.aspx", re-loads character editor(charactergeneratoredit.aspx) again.
i thought adding "e.preventdefault()" fix that, hasn't.
how can cancel button close "charactergeneratoredit.aspx" , reload "charactergeneratordisplay.aspx" in element?
thanks!
also, ensure "cancel" button not have "submit" type or return false in onclick handler.
Comments
Post a Comment