通过AJAX JQuery的发布形式不触发轨的respond_to format.js [英] JQuery posting form via AJAX not triggering rails respond_to format.js

查看:94
本文介绍了通过AJAX JQuery的发布形式不触发轨的respond_to format.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与参数的命令一个简单的形式。当我的下拉改变时,我称之为:

I have a simple form with an order by param. When my dropdown is changed, I call this:

$.post("/busca", $("#order_form").serialize(), dataType: "script")

在轨控制器身边,我有一个简单的 format.js 来处理Ajax调用。 事情是,这是行不通的。该 js.erb 模板永远不会呈现。

On the rails controller side I have a simple format.js to handle the ajax calls. Thing is that this isn't working. The js.erb template is never rendered.

我的日志显示处理由BuscaController#指数为* / * ,我不知道是什么 * / * 表示。有人可以帮我吗?

My log shows Processing by BuscaController#index as */* and I have no idea what the */* stands for. Can someone help me?

推荐答案

好了,所以我想它了。当你有一个respond_to代码块这样的:

Ok so I figured it out. When you have a respond_to block like this:

respond_to do |format|
  format.html
  format.js
end

这是行不通的。您需要设置的js第一反应比HTML之一。不要问我为什么。 这是一个对我的作品:

It will not work. You need to setup the js response first than the HTML one. Don't ask me why. This is the one that works for me:

respond_to do |format|
  format.js
  format.html
end

这篇关于通过AJAX JQuery的发布形式不触发轨的respond_to format.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆