0

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}
      );
  }

2 Answers 2

1

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);
        }
    });    
}
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.