[jQuery] bind and unbind after an Ajax Call
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<style>
<!--
/* Font Definitions */
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman";}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-reply;
font-family:Arial;
color:navy;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
{page:Section1;}
-->
</style>
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Hmmm, I actually had this same issue.
Funny thing is, this logic worked fine for me in FF (1.5) but broke in IE
(6). In my use case I was able to use $().toggle() instead which seems to work
just fine in both browsers.<o:p></o:p></span></font>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Regards,<o:p></o:p></span></font>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>-scott<o:p></o:p></span></font>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font>
<div style='border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt'>
<div>
<div class=MsoNormal align=center style='text-align:center'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>
<hr size=2 width="100%" align=center tabindex=-1>
</span></font></div>
<p class=MsoNormal><b><font size=2 face=Tahoma><span style='font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:</span></font></b><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'>
discuss-bounces@jquery.com [mailto:discuss-bounces@jquery.com] <b><span
style='font-weight:bold'>On Behalf Of </span></b>Sam Sherlock
<b><span style='font-weight:bold'>Sent:</span></b> Thursday, February 15, 2007
4:21 PM
<b><span style='font-weight:bold'>To:</span></b> jQuery Discussion.
<b><span style='font-weight:bold'>Subject:</span></b> [jQuery] bind and unbind
after an Ajax Call</span></font><o:p></o:p>
</div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>I have links with the class name 'jLink' that update
After each AJAX Call I re-run a function named init (which is initially called
via document ready)
It does work but after two sometimes three clicks it stop working any ideas?
this is the unbind / bind is inside that init function
function
init()
{
....
if(siteOptions.page.isInit)
{
siteOptions.page.isInit = true;
$("a.jLink")
.unbind('click')
.bind(
'click',
{href: this.href},
function(event)
{
event.stopPropagation ();
event.preventDefault();
jLinkCall(this.href);
}
);
}
....
}
function jLinkCall(jHref)
{
var regex =
'^(.*)\/([a-zA-Z0-9]*)\/([a-zA-Z]*)\/([a-zA-Z]*)\/([0-9]*)([\/]*)([0-9]*)([\/]*)$';
var viewURL = new String(jHref), dataURL = "", params = {}, re = new
RegExp(regex, "g"), dataURL = "";
var m = re.exec(viewURL);
if (m !== null) {
dataURL = m[1] + '/' + m[2] + '/' + m[3] + '/' + m[4] + '/'
+ m[5] + '/' + ((m[7]) ? m[7]: 1) + '/data/';
}
$("div#main").SlideInUp(
500,
function() {},
'easein'
).empty();
$.getJSON(
dataURL,
function(json) {
$("#main").html("<div id=\"innerMain\">" +
json.data + "</div>");
$('#top').ScrollTo(800, 'easeout');
$('div#main').SlideOutDown(500, function() {
jLinkComplete();
},
'easeout');
}
); // /getJSON
} // jLinkCall()
function jLinkComplete()
{
siteOptions.page.isInit = false;
init();
} // jLinkComplete() <o:p></o:p></span></font>
</div>
</div>
</body>
</html>
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/