简体   繁体   English

javascript未捕获的类型错误函数ajax

[英]javascript uncaught type error function ajax

Below you can see two functions. 在下面您可以看到两个功能。 The second works perfectly. 第二个完美地工作。 It submits data when a select menu has been changed. 选择菜单更改后,它将提交数据。

I am trying to apply a similar logic but this time to a field. 我正在尝试将类似的逻辑应用于此领域。 When the value in the field as changed I want to the data to submit, as seen in the first bit of js 当字段中的值更改时,我想将数据提交,如js的第一部分所示

Despite the logic being almost the same I get this error 尽管逻辑几乎相同,但我仍然收到此错误

Uncaught ReferenceError: $ is not defined
9452:382 (anonymous function)

If someone could illuminate to me what exactly this and how I fix it I'd be very grateful. 如果有人能向我阐明这到底是什么以及我如何解决它,我将不胜感激。 My assumption is that its something related to the order in which things load, however as the logic is no different from the old logic surely this shouldnt be a problem. 我的假设是它与事物加载的顺序有关,但是由于逻辑与旧逻辑没有什么不同,因此这肯定不是问题。

 :javascript

    $('#booking_package_#{package.id}').on("keyup change", function(){
      var bookingPackageQuantity = document.getElementById("menu_item_#{package.id}");
      $.ajax({
        url: "/venues/#{venue.id}/bookings/#{booking.id}/booking_packages/#{@booking_package.id}/add_menu_item?menu_item_id="+bookingPackageQuantity,
        type: "GET"
      })
    });


    $('#menu_item_#{package.id}').on("change", function(){
      var selects = document.getElementById("menu_item_#{package.id}");
      var menuItemId = selects.options[selects.selectedIndex].value
      $.ajax({
        url: "/venues/#{venue.id}/bookings/#{booking.id}/booking_packages/#{@booking_package.id}/add_menu_item?menu_item_id="+menuItemId,
        type: "GET"
      })
    });

I am trying to bind the event to this field 我试图将事件绑定到此字段

    = number_field_tag 'quantity', booking.find_package(package).quantity, id: "booking_package_#{package.id}"

In the first part of the JS, please put value. 在JS的第一部分中,请输入值。 Probably that may be breaking the javascript, please try the following edited code... 可能破坏了javascript,请尝试以下已编辑的代码...

 $('#booking_package_#{package.id}').on("keyup change", function(){
  var bookingPackageQuantity = document.getElementById("menu_item_#{package.id}");
  $.ajax({
    url: "/venues/#{venue.id}/bookings/#{booking.id}/booking_packages/#{@booking_package.id}/add_menu_item?menu_item_id="+bookingPackageQuantity.value,
    type: "GET"
  })
});

Can you please let me know if you are using any frameworks for this? 您能否让我知道您是否正在使用任何框架? so that i can help you better... 这样我可以更好地帮助您...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM