views:

22

answers:

1

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?

A: 

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.

Patrick Steele
Thanks for the quick response. Yes $j is for jQuery, I tried changing it to $jQuery and it still gives the same parsing error. Does this mean that all jQuery code has to be within external js files in MonoRail??
Justin
Not "$jQuery" -- I thought you could use just "jQuery" (no dollar sign and therefore it won't trip up nVelocity). Although I've used MonoRail with prototype and I believe it uses the "$" too. Try just "jQuery" and I'll dig around some of my old .vm files.
Patrick Steele
Thanks, that worked!
Justin