ajax and event binding confusion
I'm getting moderately confused while trying to use ajax for rendering
a page...
In short, the docs says that:
"html": Returns HTML as plain text; included script tags are
evaluated when inserted in the DOM. [1]
1. Is there any method or trick that could be used that can be used so
that the returned
html data can be later used for, say, binding an event to a subsequent
function ?
Thus, any calls such as:
$('#' + 'fooId').bind('click', function() {
// handle the click event
return false;
});
would fail, since it seems that the script won't get evaluted if
returned using
XMLHttpRequest... :(
2. Is it allowed to have multiple $(function() { /* do stuff here
*/ }); invocations
per (xml) http request ?
Thanks for any help or guidance!
Etienne
$.ajaxSetup({
dataType: 'html',
type: 'GET',
cache: false, // set this to false if debugging
async: false, // set this to false if debugging
global: true,
processData: true,
timeout: 300,
error: function(xhr, msg) {
// XXX: Handle generic error responses here.
$('<div>' + 'the server croaked: ' + msg + '</
div>').prependTo($('#page').empty());
},
success: function(data, msg) {
// function to call upon successful
// ajax request
var innerHTML = $(data).children('#' + pageId).html();
var page = $('#' + pageId);
$('<img src=' + '"' + imageUrl + '"' + ' /