In a very recent questions I was having problems with this. My code was:
$("#SearchResults").load("/Invoice/InvoiceSearchResults/");
And I was advised to use this instead:
$.ajax({
url: "/Invoice/InvoiceSearchResults/",
type: 'GET',
dataType: 'html', // <-- to expect an html response
success: doSubmitSuccess
});
with:
function doSubmitSuccess(result) {
$(".SearchResults").html(result);
}
And then someone else kindly tried to help me with:
$.get(postUrl, function(data) {
$("#posts").append(data);
$('#ajaxLdMore').addClass('hideElement');
$('#ldMore').removeClass('hideElement');
});
It turns out my problem was I'm in idiot abd was using the selector '#' instead of '.'
I'm just wondering should I swap my code for any of these?
Are there real pros and cons of each approach or is it preference?
Is there a better way that nobody has yet posted?
I'm not trying to open up a huge debate (i don't think :) ) - I just want to understand a bit more about it.
Thanks