gpt4 book ai didi

jquery - Rails 3 表格远程不工作

转载 作者:行者123 更新时间:2023-12-01 08:17:08 25 4
gpt4 key购买 nike

我的 ajaxy 调用不起作用,然后它随机开始工作,然后当我添加更多 CoffeeScript 时它停止工作。我删除了添加的 CoffeeScript ,但仍然不起作用。

我注意到 rails.js 没有被加载(通过 firebug/Chrome 检查器检查)。 Rails 3.2.1 中 rails.js 是否已被 jquery_ujs.js 取代?我启动了一个新项目,发现 rails.js 也不在那里。

表格如下:

<%= form_tag("#{tybleau_api_path}.json", remote: true, id: "sportForm", :'data-type' => 'json' ) do%>
<%= select_tag("state", options_from_collection_for_select(@states, "HometownState", "HometownState"), prompt: "Choose a State", class: "submittable") %>
<%= submit_tag "Update View" %>
<% end %>

当我单击“更新 View ”时,控制台显示此内容:

Started POST "/tybleau/api.json" for 127.0.0.1 at 2012-03-22 17:40:03 -0700
Processing by TybleauController#api as JSON
Parameters: {"utf8"=>"✓", "authenticity_token"=>"I6752Fit6cCIuASMr4/FD+yLTEBrS2oPhnNBbJQE67k=", "state"=>"AZ", "commit"=>"Update View"}
Player Load (745.1ms) SELECT FirstName FROM `players` INNER JOIN `players_to_teams` ON `players_to_teams`.`player_id` = `players`.`id` INNER JOIN `teams` ON `teams`.`id` = `players_to_teams`.`team_id` WHERE `teams`.`SportTypeId` = 2 AND `players`.`hometownstate` = 'AZ'
EXPLAIN (0.4ms) EXPLAIN SELECT FirstName FROM `players` INNER JOIN `players_to_teams` ON `players_to_teams`.`player_id` = `players`.`id` INNER JOIN `teams` ON `teams`.`id` = `players_to_teams`.`team_id` WHERE `teams`.`SportTypeId` = 2 AND `players`.`hometownstate` = 'AZ'
EXPLAIN for: SELECT FirstName FROM `players` INNER JOIN `players_to_teams` ON `players_to_teams`.`player_id` = `players`.`id` INNER JOIN `teams` ON `teams`.`id` = `players_to_teams`.`team_id` WHERE `teams`.`SportTypeId` = 2 AND `players`.`hometownstate` = 'AZ'
+----+-------------+------------------+--------+---------------+---------+---------+----------------------------------------------+--------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+------------------+--------+---------------+---------+---------+----------------------------------------------+--------+-------------+
| 1 | SIMPLE | players_to_teams | ALL | NULL | NULL | NULL | NULL | 260239 | |
| 1 | SIMPLE | players | eq_ref | PRIMARY | PRIMARY | 4 | mysql_development.players_to_teams.player_id | 1 | Using where |
| 1 | SIMPLE | teams | eq_ref | PRIMARY | PRIMARY | 4 | mysql_development.players_to_teams.team_id | 1 | Using where |
+----+-------------+------------------+--------+---------------+---------+---------+----------------------------------------------+--------+-------------+
3 rows in set (0.00 sec)

Completed 200 OK in 1034ms (Views: 154.7ms | ActiveRecord: 825.9ms)

所以我知道它有效。如果我删除对 remote: true 的调用,我会得到 json 对象形式的预期结果。

这是我的 CoffeeScript :

jQuery ->
$("#sportForm")
.bind 'ajax:beforeSend', (xhr, settings) ->
alert 'loading'
.bind 'ajax:success', (data, status, xhr) ->
alert 'success'
.bind 'ajac:complete', (xhr, status) ->
alert 'success'
.bind 'ajax:error', (xhr, status, error) ->
alert 'error'

里面有错别字或者什么吗? Rails.js 应该在 firebug 中可见吗?

谢谢

最佳答案

事实证明问题出在 SlickGrid 上。 SlickGrid 或所需的 jQuery-UI 库之一存在一些命名问题,并且窃取了 ajax 响应的焦点。我决定使用 SlickGrid 以外的其他工具,因此我从未完全诊断出问题,但它没有任何作用。

注意

在 Rails 3.2.1 中,没有 rails.js,而是 jquery_ujs.js

感谢您的帮助

关于jquery - Rails 3 表格远程不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9832682/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com