You should use a container inside the body and not place the code directly in the body.
ie. Add on the div tag inside the body which will be the container
<div class="container"></div>
Then on the JS call
$( '.container' ).html( response ).show('slow');
That way the content loads in the container and not directly in the body which would replace all the content of the page including the JS you have there.
Also when using Ajax calls I believe it makes for a cleaner code to pass the response to other functions to process. That way you will have smaller functions to debug and easier to understand code.
$.ajax({
url: 'ajax/test.html',
success: function(data) {
//Here you pass the response to the other function
processSuccess(data);
},
fail: function(data) {
//Here you pass the response to the other function
processFail(data);
}
});
function processSuccess(response) {
//Print the response in the console (ie. Firebug console)
//if console is available
if(console) {
console.log(response);
}
};
function processFail(response) {
//Print the response in the console (ie. Firebug console)
//if console is available
if(console) {
console.log(response);
}
};
Of course all that inside a namespace would make it even better.