How would I convert the following prototype-based js code to jQuery? I'm stripping prototype out of an existing site that is having jQuery integrated into it and there are just a few pieces of code like this that were dependent on prototype:
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}
);
}
Try this
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);
}
});
}
Just an addition to the answer of Minesh Patel. In jQuery 1.8 on the jqXHR object (returned by $.ajax) success
is replaced by done
, error
with fail
and complete
by always
. If you want to be up to date you should use done
instead of success.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.