Ajax loaded content , jquery plugins not working
Posted
by Sylph
on Stack Overflow
See other posts from Stack Overflow
or by Sylph
Published on 2010-05-20T01:21:49Z
Indexed on
2010/05/20
1:30 UTC
Read the original article
Hit count: 319
Hello,
I have a link that calls the ajax to load content, and after the content is loaded, my jquery function doesn't work anymore
Here is my HTML
<a href="#" onclick="javascript:makeRequest('content.html','');">Load Content</a>
<span id="result">
<table id="myTable" valign="top" class="tablesorter">
<thead>
<tr>
<th>Title 1</th>
<th>Level 1</th>
<th>Topics</th>
<th>Resources</th>
</tr>
</thead>
<tbody>
<tr>
<td>Example title 1</td>
<td>Example level 1</td>
</tr>
<tr>
<td>Example title 2</td>
<td>Example level 2</td>
</tr>
</tbody>
</table>
</span>
The table is sorted using jquery table sorter plugin from http://tablesorter.com/docs/ After the ajax content is loaded, another set of table with different data will be displayed. However, the sorting doesn't work anymore.
Here is my ajax script which is use to load the content :
var http_request = false;
function makeRequest(url, parameters) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
// set type accordingly to anticipated content type
//http_request.overrideMimeType('text/xml');
http_request.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
http_request.onreadystatechange = alertContents;
http_request.open('GET', url + parameters, true);
http_request.send(null);
}
function alertContents() {
if (http_request.readyState == 4) {
// alert(http_request.status);
if (http_request.status == 200) {
//alert(http_request.responseText);
result = http_request.responseText;
document.getElementById('result').innerHTML = result;
} else {
alert('There was a problem with the request.');
}
}
}
Any idea how I can get the jquery plugins to work after the content is loaded?
I have searched and changed the jquery.tablesorter.js click function into live() like this $headers.live("click",function(e)
but it doesn't work as well.
How can I make the jquery functions to work after the content is loaded? Thank you
© Stack Overflow or respective owner