在最近的一個問題中,我遇到了問題。我的代碼是:使用JQuery在ASP.Net MVC中加載部分視圖 - 哪種方法是首選?
$("#SearchResults").load("/Invoice/InvoiceSearchResults/");
而且有人建議我改用此:
$.ajax({
url: "/Invoice/InvoiceSearchResults/",
type: 'GET',
dataType: 'html', // <-- to expect an html response
success: doSubmitSuccess
});
有:
function doSubmitSuccess(result) {
$(".SearchResults").html(result);
}
然後別人好心試圖幫助我與:
$.get(postUrl, function(data) {
$("#posts").append(data);
$('#ajaxLdMore').addClass('hideElement');
$('#ldMore').removeClass('hideElement');
});
事實證明我的問題是我在白癡abd是使用選擇器'#'而不是'。'。
我只是想知道我應該交換我的代碼的任何這些?
每種方法是否存在真正的優缺點還是偏好?
還有沒有人發佈過的更好的方法?
我不想打開一個巨大的辯論(我不認爲:)) - 我只是想更多地瞭解它。
感謝