Search code examples
castle-monorail

MonoRail - How to write JavaScript within .vm page


I'm using MonoRail and tried to write a tag within a .vm view to write some JavaScript:

<script type="text/javascript">
  //<![CDATA[
  $j(document).ready(function()
  {
  $j('#business_parentbusinesstype_id').change(function()
  {
  $j.ajax({
  url:'http://localhost:88/admin/business/GetChildBusinessTypes',
  data: { parentId: $j('#business_parentbusinesstype_id').val() },
  dataType: 'script'
  });
  });
  });
  //]]>
</script>

You would think that this would work since it's an HTML page but it gives me this error:

Unable to process resource 'admin\business\new.vm': Encountered "\r\n url:\'http://localhost:88/admin/business/GetChildBusinessTypes\',\r\n data: { parentId: " at line 7, column 12. Was expecting: ...

What am I missing?


Solution

  • I'm wondering if nVelocity is seeing the "$j" and trying to find it in the property bag and execute the "ajax" method. If the "$j" is the short-hand for jQuery, try changing it to the full "jQuery" and see if that works.