Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Rails:提交表单而不重新加载页面_Javascript_Ruby On Rails_Ruby On Rails 4_Google Earth - Fatal编程技术网

Javascript Rails:提交表单而不重新加载页面

Javascript Rails:提交表单而不重新加载页面,javascript,ruby-on-rails,ruby-on-rails-4,google-earth,Javascript,Ruby On Rails,Ruby On Rails 4,Google Earth,我的应用程序()有两个部分: Google Earth窗格,其中显示视图 一个表单,用户在其中设置他想要设置相机的地址/高度 当用户提交表单时,我希望RoR后端存储用户设置的参数,JS前端更新视图。我让两个独立的部分工作 当用户提交Rail表单时,它会重新加载页面并“重置”相机 理想情况下,我希望表单在不重新加载页面的情况下将数据提交到后端-这可能吗?或者我完全错了?发布一些代码会有所帮助,但请尝试在表单中添加“remote:true”。这将告诉您的页面在提交时不要刷新 此外,您还需要在控制

我的应用程序()有两个部分:

  • Google Earth窗格,其中显示视图
  • 一个表单,用户在其中设置他想要设置相机的地址/高度
当用户提交表单时,我希望RoR后端存储用户设置的参数,JS前端更新视图。我让两个独立的部分工作

当用户提交Rail表单时,它会重新加载页面并“重置”相机


理想情况下,我希望表单在不重新加载页面的情况下将数据提交到后端-这可能吗?或者我完全错了?

发布一些代码会有所帮助,但请尝试在表单中添加“remote:true”。这将告诉您的页面在提交时不要刷新

此外,您还需要在控制器中创建一个新方法来转发以响应您的提交,并在视图文件夹(可能是js.erb文件)中创建一个页面来重新加载数据。 在看不到代码的情况下,下面是一个简单的步骤示例:

app/assets/views/google_earth/index.html.erb

在路由文件中:

get 'camera' => 'google_earth#cameraUpdate', as: 'camera'
app/assets/views/google_earth/camera.js.erb

$('#camera-pane').html("<%= escape_javascript(render partial: 'camera_view', :locals => { x_coord: @x, y_coord: @y }) %>");

发布一些代码会有所帮助,但请尝试在表单中添加“remote:true”。这将告诉您的页面在提交时不要刷新

此外,您还需要在控制器中创建一个新方法来转发以响应您的提交,并在视图文件夹(可能是js.erb文件)中创建一个页面来重新加载数据。 在看不到代码的情况下,下面是一个简单的步骤示例:

app/assets/views/google_earth/index.html.erb

在路由文件中:

get 'camera' => 'google_earth#cameraUpdate', as: 'camera'
app/assets/views/google_earth/camera.js.erb

$('#camera-pane').html("<%= escape_javascript(render partial: 'camera_view', :locals => { x_coord: @x, y_coord: @y }) %>");
使用jQuery: 带导轨: xxx.html.erb

<%= link_to 'Daily Collection', 'daily_collection', class: "btn btn-info", method: 'get', remote: true %>
get   'daily_collection' => 'patients#daily_collection'
class Patients
   def daily_collection
      do something...
   end
end
<p>to be appended with the called page </p>
$('#price_daily').html('<%= escape_javascript(render :partial => 'collection_money') %>');
患者\u控制器.rb

<%= link_to 'Daily Collection', 'daily_collection', class: "btn btn-info", method: 'get', remote: true %>
get   'daily_collection' => 'patients#daily_collection'
class Patients
   def daily_collection
      do something...
   end
end
<p>to be appended with the called page </p>
$('#price_daily').html('<%= escape_javascript(render :partial => 'collection_money') %>');
collection\u money.html.erb

<%= link_to 'Daily Collection', 'daily_collection', class: "btn btn-info", method: 'get', remote: true %>
get   'daily_collection' => 'patients#daily_collection'
class Patients
   def daily_collection
      do something...
   end
end
<p>to be appended with the called page </p>
$('#price_daily').html('<%= escape_javascript(render :partial => 'collection_money') %>');
将与被调用的页面一起追加

daily_collection.js.erb

<%= link_to 'Daily Collection', 'daily_collection', class: "btn btn-info", method: 'get', remote: true %>
get   'daily_collection' => 'patients#daily_collection'
class Patients
   def daily_collection
      do something...
   end
end
<p>to be appended with the called page </p>
$('#price_daily').html('<%= escape_javascript(render :partial => 'collection_money') %>');
$('price#u daily').html('collection_money')%>;
更多参考:
使用jQuery: 带导轨: xxx.html.erb

<%= link_to 'Daily Collection', 'daily_collection', class: "btn btn-info", method: 'get', remote: true %>
get   'daily_collection' => 'patients#daily_collection'
class Patients
   def daily_collection
      do something...
   end
end
<p>to be appended with the called page </p>
$('#price_daily').html('<%= escape_javascript(render :partial => 'collection_money') %>');
患者\u控制器.rb

<%= link_to 'Daily Collection', 'daily_collection', class: "btn btn-info", method: 'get', remote: true %>
get   'daily_collection' => 'patients#daily_collection'
class Patients
   def daily_collection
      do something...
   end
end
<p>to be appended with the called page </p>
$('#price_daily').html('<%= escape_javascript(render :partial => 'collection_money') %>');
collection\u money.html.erb

<%= link_to 'Daily Collection', 'daily_collection', class: "btn btn-info", method: 'get', remote: true %>
get   'daily_collection' => 'patients#daily_collection'
class Patients
   def daily_collection
      do something...
   end
end
<p>to be appended with the called page </p>
$('#price_daily').html('<%= escape_javascript(render :partial => 'collection_money') %>');
将与被调用的页面一起追加

daily_collection.js.erb

<%= link_to 'Daily Collection', 'daily_collection', class: "btn btn-info", method: 'get', remote: true %>
get   'daily_collection' => 'patients#daily_collection'
class Patients
   def daily_collection
      do something...
   end
end
<p>to be appended with the called page </p>
$('#price_daily').html('<%= escape_javascript(render :partial => 'collection_money') %>');
$('price#u daily').html('collection_money')%>;
更多参考:

不在这里-你是说我应该吗?@FrancescoBovoli他是说,hot你发送ajax请求吗?添加
remote:true
应该可以。不在这里-你是说我应该吗?@FrancescoBovoli他是说,hot你发送ajax请求吗?添加
remote:true
应该可以。是的,remote:true是我缺少的。我在这里找到的Rails文档中也解释过(在你把我放到正确的机架上之后):是的,remote:true是我缺少的。我在这里找到的Rails文档中也解释了(在您将我放在正确的机架上之后):