Search code examples
jqueryajaxload

jQuery: modify responseText in load() function


Is it possible to modify the responseText before adding to the element?

$('#target').load('script.php', params, function(response,status,xhr){
    response         = 'foo';  // doesn't work
    xhr.responseText = 'foo';  // doesn't work
    return 'foo';              // doesn't work        
})

I imagine the only way to get what I want is to use the ajax method and populate my target upon success.


Solution

  • You'll have to use jQuery's get method:

    $.get('script.php', params, function (responseText) {
        $('#target').html( responseText + 'foo' );
    });