如何将以下基于原型的js代码转换为jQuery?我正在将原型从已经集成了jQuery的现有站点中剥离出来,并且只有几段代码依赖于原型:
function updateJobSubCategory(blockToUpdate, ParentID){
var url = '/resource/ajax/selectCategories.cfm';
var params = 'multiple=1&ParentID=' + ParentID + '&selectedList=' + CategoryList($('SubCategoryIDs'));
$(blockToUpdate).innerHTML = "<div>Loading...</div>";
var ajax = new Ajax.Updater(
{success: blockToUpdate},
url,
{method: 'post', parameters: params}
);
}
答案 0 :(得分:1)
试试这个
function updateJobSubCategory(blockToUpdate, ParentID)
{
var url = '/resource/ajax/selectCategories.cfm';
var params = 'multiple=1&ParentID=' + ParentID + '&selectedList=' + CategoryList(jQuery('SubCategoryIDs'));
jQuery("#"+blockToUpdate).html("<div>Loading...</div>");
jQuery.ajax({
dataType: "html",
type: "POST",
evalScripts: true,
url: url,
data: params,
success: function (data, textStatus){
jQuery("#"+blockToUpdate).html(data);
}
});
}
答案 1 :(得分:0)
只是Minesh Patel答案的补充。在jqXHR对象的jQuery 1.8中(由$ .ajax返回)success
由done
替换,error
替换为fail
,complete
替换为always
}。如果您想要更新,则应使用done
而不是成功。