ajax in ruby on rails doesn t send the data
i am doing a test of ajax (because i am so new in ajax) to send data from the view welcome(index.html.erb) to the controller(welcome_controller.rb) but all the times that i have tried show me the same error:
with same change:
but i don t know what that mean and all the the times the view show me the alert "error"(error) when i do the request.
here is what i have done in the view:
<%= javascript_include_tag "application" %>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
$(document).ready(function(){
$("#petition").click(function(){
$.ajax({
url: 'http://192.168.99.100:3000/welcome_controller/index/',
type: 'POST',
dataType: 'json',
data: { max_id: {id: "5"} },
success: function (data) {
alert("success");
},
error: function(xhr, status, error) {
alert(xhr+status+error); \to take the second photo i change this for this "alert(JSON.stringify(xhr));"
}
});
});
});
here is my routes.rb:
Rails.application.routes.draw do
resources :welcome do
collection do
get 'index'
end
end
get 'welcome/page'
root 'welcome#index'
get 'menu/index'
end
here is me application.js:
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require tinymce
//= require rails-ujs
//= require turbolinks
//= require_tree .
and here is the ruby gem:
# frozen_string_literal: true
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/')
"https://github.com/#{repo_name}.git"
end
#propiedades de usuario
gem 'devise', '~> 4.4', '>= 4.4.1'
#text editor to post with link and imagens
gem 'tinymce-rails'
#admin y moderator
gem 'cancancan'
gem 'rolify'
#votar like y dislike
gem 'acts_as_votable', '~> 0.11.1'
#consultas rails para mesclar con js
gem 'jquery-rails'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.5'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 3.7'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: %i[mri mingw x64_mingw]
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '~> 2.13'
gem 'selenium-webdriver'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'web-console', '>= 3.3.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
my controller name is :welcome_controller.rb
and have 2 method index and show i will put the controller anyways:
class WelcomeController < ApplicationController
before_action :set_welcome, only: [:show]
protect_from_forgery :except => :receive_guest
helper_method :current_or_guest_user
def index
puts params[:max_id]
end
def show
end
end
javascript ruby-on-rails ajax url post
add a comment |
i am doing a test of ajax (because i am so new in ajax) to send data from the view welcome(index.html.erb) to the controller(welcome_controller.rb) but all the times that i have tried show me the same error:
with same change:
but i don t know what that mean and all the the times the view show me the alert "error"(error) when i do the request.
here is what i have done in the view:
<%= javascript_include_tag "application" %>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
$(document).ready(function(){
$("#petition").click(function(){
$.ajax({
url: 'http://192.168.99.100:3000/welcome_controller/index/',
type: 'POST',
dataType: 'json',
data: { max_id: {id: "5"} },
success: function (data) {
alert("success");
},
error: function(xhr, status, error) {
alert(xhr+status+error); \to take the second photo i change this for this "alert(JSON.stringify(xhr));"
}
});
});
});
here is my routes.rb:
Rails.application.routes.draw do
resources :welcome do
collection do
get 'index'
end
end
get 'welcome/page'
root 'welcome#index'
get 'menu/index'
end
here is me application.js:
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require tinymce
//= require rails-ujs
//= require turbolinks
//= require_tree .
and here is the ruby gem:
# frozen_string_literal: true
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/')
"https://github.com/#{repo_name}.git"
end
#propiedades de usuario
gem 'devise', '~> 4.4', '>= 4.4.1'
#text editor to post with link and imagens
gem 'tinymce-rails'
#admin y moderator
gem 'cancancan'
gem 'rolify'
#votar like y dislike
gem 'acts_as_votable', '~> 0.11.1'
#consultas rails para mesclar con js
gem 'jquery-rails'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.5'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 3.7'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: %i[mri mingw x64_mingw]
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '~> 2.13'
gem 'selenium-webdriver'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'web-console', '>= 3.3.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
my controller name is :welcome_controller.rb
and have 2 method index and show i will put the controller anyways:
class WelcomeController < ApplicationController
before_action :set_welcome, only: [:show]
protect_from_forgery :except => :receive_guest
helper_method :current_or_guest_user
def index
puts params[:max_id]
end
def show
end
end
javascript ruby-on-rails ajax url post
The$.ajax
call in your JavaScript isn't the problem, the problem is how you're trying to include jQuery in the page. You should probably havegem 'jquery-rails'
in your Gemfile and//= require jquery3
in yourapp/assets/javascript/application.js
file.
– mu is too short
Nov 21 '18 at 21:08
you don't need to add jquery with a script tag, you already have it on your application.js, and also you are adding jquery twice with different versions with two script tags, just remove all and leave the application.js reference to jquery, then check the browser console and see if there's any error when running the site
– arieljuod
Nov 22 '18 at 1:36
add a comment |
i am doing a test of ajax (because i am so new in ajax) to send data from the view welcome(index.html.erb) to the controller(welcome_controller.rb) but all the times that i have tried show me the same error:
with same change:
but i don t know what that mean and all the the times the view show me the alert "error"(error) when i do the request.
here is what i have done in the view:
<%= javascript_include_tag "application" %>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
$(document).ready(function(){
$("#petition").click(function(){
$.ajax({
url: 'http://192.168.99.100:3000/welcome_controller/index/',
type: 'POST',
dataType: 'json',
data: { max_id: {id: "5"} },
success: function (data) {
alert("success");
},
error: function(xhr, status, error) {
alert(xhr+status+error); \to take the second photo i change this for this "alert(JSON.stringify(xhr));"
}
});
});
});
here is my routes.rb:
Rails.application.routes.draw do
resources :welcome do
collection do
get 'index'
end
end
get 'welcome/page'
root 'welcome#index'
get 'menu/index'
end
here is me application.js:
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require tinymce
//= require rails-ujs
//= require turbolinks
//= require_tree .
and here is the ruby gem:
# frozen_string_literal: true
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/')
"https://github.com/#{repo_name}.git"
end
#propiedades de usuario
gem 'devise', '~> 4.4', '>= 4.4.1'
#text editor to post with link and imagens
gem 'tinymce-rails'
#admin y moderator
gem 'cancancan'
gem 'rolify'
#votar like y dislike
gem 'acts_as_votable', '~> 0.11.1'
#consultas rails para mesclar con js
gem 'jquery-rails'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.5'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 3.7'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: %i[mri mingw x64_mingw]
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '~> 2.13'
gem 'selenium-webdriver'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'web-console', '>= 3.3.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
my controller name is :welcome_controller.rb
and have 2 method index and show i will put the controller anyways:
class WelcomeController < ApplicationController
before_action :set_welcome, only: [:show]
protect_from_forgery :except => :receive_guest
helper_method :current_or_guest_user
def index
puts params[:max_id]
end
def show
end
end
javascript ruby-on-rails ajax url post
i am doing a test of ajax (because i am so new in ajax) to send data from the view welcome(index.html.erb) to the controller(welcome_controller.rb) but all the times that i have tried show me the same error:
with same change:
but i don t know what that mean and all the the times the view show me the alert "error"(error) when i do the request.
here is what i have done in the view:
<%= javascript_include_tag "application" %>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
$(document).ready(function(){
$("#petition").click(function(){
$.ajax({
url: 'http://192.168.99.100:3000/welcome_controller/index/',
type: 'POST',
dataType: 'json',
data: { max_id: {id: "5"} },
success: function (data) {
alert("success");
},
error: function(xhr, status, error) {
alert(xhr+status+error); \to take the second photo i change this for this "alert(JSON.stringify(xhr));"
}
});
});
});
here is my routes.rb:
Rails.application.routes.draw do
resources :welcome do
collection do
get 'index'
end
end
get 'welcome/page'
root 'welcome#index'
get 'menu/index'
end
here is me application.js:
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require tinymce
//= require rails-ujs
//= require turbolinks
//= require_tree .
and here is the ruby gem:
# frozen_string_literal: true
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/')
"https://github.com/#{repo_name}.git"
end
#propiedades de usuario
gem 'devise', '~> 4.4', '>= 4.4.1'
#text editor to post with link and imagens
gem 'tinymce-rails'
#admin y moderator
gem 'cancancan'
gem 'rolify'
#votar like y dislike
gem 'acts_as_votable', '~> 0.11.1'
#consultas rails para mesclar con js
gem 'jquery-rails'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.5'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 3.7'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: %i[mri mingw x64_mingw]
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '~> 2.13'
gem 'selenium-webdriver'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'web-console', '>= 3.3.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
my controller name is :welcome_controller.rb
and have 2 method index and show i will put the controller anyways:
class WelcomeController < ApplicationController
before_action :set_welcome, only: [:show]
protect_from_forgery :except => :receive_guest
helper_method :current_or_guest_user
def index
puts params[:max_id]
end
def show
end
end
javascript ruby-on-rails ajax url post
javascript ruby-on-rails ajax url post
edited Nov 23 '18 at 15:50
mrpepo877
asked Nov 21 '18 at 20:04
mrpepo877mrpepo877
10710
10710
The$.ajax
call in your JavaScript isn't the problem, the problem is how you're trying to include jQuery in the page. You should probably havegem 'jquery-rails'
in your Gemfile and//= require jquery3
in yourapp/assets/javascript/application.js
file.
– mu is too short
Nov 21 '18 at 21:08
you don't need to add jquery with a script tag, you already have it on your application.js, and also you are adding jquery twice with different versions with two script tags, just remove all and leave the application.js reference to jquery, then check the browser console and see if there's any error when running the site
– arieljuod
Nov 22 '18 at 1:36
add a comment |
The$.ajax
call in your JavaScript isn't the problem, the problem is how you're trying to include jQuery in the page. You should probably havegem 'jquery-rails'
in your Gemfile and//= require jquery3
in yourapp/assets/javascript/application.js
file.
– mu is too short
Nov 21 '18 at 21:08
you don't need to add jquery with a script tag, you already have it on your application.js, and also you are adding jquery twice with different versions with two script tags, just remove all and leave the application.js reference to jquery, then check the browser console and see if there's any error when running the site
– arieljuod
Nov 22 '18 at 1:36
The
$.ajax
call in your JavaScript isn't the problem, the problem is how you're trying to include jQuery in the page. You should probably have gem 'jquery-rails'
in your Gemfile and //= require jquery3
in your app/assets/javascript/application.js
file.– mu is too short
Nov 21 '18 at 21:08
The
$.ajax
call in your JavaScript isn't the problem, the problem is how you're trying to include jQuery in the page. You should probably have gem 'jquery-rails'
in your Gemfile and //= require jquery3
in your app/assets/javascript/application.js
file.– mu is too short
Nov 21 '18 at 21:08
you don't need to add jquery with a script tag, you already have it on your application.js, and also you are adding jquery twice with different versions with two script tags, just remove all and leave the application.js reference to jquery, then check the browser console and see if there's any error when running the site
– arieljuod
Nov 22 '18 at 1:36
you don't need to add jquery with a script tag, you already have it on your application.js, and also you are adding jquery twice with different versions with two script tags, just remove all and leave the application.js reference to jquery, then check the browser console and see if there's any error when running the site
– arieljuod
Nov 22 '18 at 1:36
add a comment |
1 Answer
1
active
oldest
votes
when you have jquery gem in your gem files
you can include jquery library using
//= require jquery
in your application.js
which you already have done .
you need to remove these lines from your views
<script src="jquery-3.3.1.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
and replace them with this line
<%= javascript_include_tag "application" %>
thanks for the help in that part of my code, really thanks, but i was referred to other error that i can t see, i don t know why (i update the question to give more information)
– mrpepo877
Nov 23 '18 at 15:42
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419716%2fajax-in-ruby-on-rails-doesn-t-send-the-data%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
when you have jquery gem in your gem files
you can include jquery library using
//= require jquery
in your application.js
which you already have done .
you need to remove these lines from your views
<script src="jquery-3.3.1.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
and replace them with this line
<%= javascript_include_tag "application" %>
thanks for the help in that part of my code, really thanks, but i was referred to other error that i can t see, i don t know why (i update the question to give more information)
– mrpepo877
Nov 23 '18 at 15:42
add a comment |
when you have jquery gem in your gem files
you can include jquery library using
//= require jquery
in your application.js
which you already have done .
you need to remove these lines from your views
<script src="jquery-3.3.1.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
and replace them with this line
<%= javascript_include_tag "application" %>
thanks for the help in that part of my code, really thanks, but i was referred to other error that i can t see, i don t know why (i update the question to give more information)
– mrpepo877
Nov 23 '18 at 15:42
add a comment |
when you have jquery gem in your gem files
you can include jquery library using
//= require jquery
in your application.js
which you already have done .
you need to remove these lines from your views
<script src="jquery-3.3.1.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
and replace them with this line
<%= javascript_include_tag "application" %>
when you have jquery gem in your gem files
you can include jquery library using
//= require jquery
in your application.js
which you already have done .
you need to remove these lines from your views
<script src="jquery-3.3.1.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
and replace them with this line
<%= javascript_include_tag "application" %>
answered Nov 22 '18 at 14:07
Remon AminRemon Amin
7531236
7531236
thanks for the help in that part of my code, really thanks, but i was referred to other error that i can t see, i don t know why (i update the question to give more information)
– mrpepo877
Nov 23 '18 at 15:42
add a comment |
thanks for the help in that part of my code, really thanks, but i was referred to other error that i can t see, i don t know why (i update the question to give more information)
– mrpepo877
Nov 23 '18 at 15:42
thanks for the help in that part of my code, really thanks, but i was referred to other error that i can t see, i don t know why (i update the question to give more information)
– mrpepo877
Nov 23 '18 at 15:42
thanks for the help in that part of my code, really thanks, but i was referred to other error that i can t see, i don t know why (i update the question to give more information)
– mrpepo877
Nov 23 '18 at 15:42
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419716%2fajax-in-ruby-on-rails-doesn-t-send-the-data%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The
$.ajax
call in your JavaScript isn't the problem, the problem is how you're trying to include jQuery in the page. You should probably havegem 'jquery-rails'
in your Gemfile and//= require jquery3
in yourapp/assets/javascript/application.js
file.– mu is too short
Nov 21 '18 at 21:08
you don't need to add jquery with a script tag, you already have it on your application.js, and also you are adding jquery twice with different versions with two script tags, just remove all and leave the application.js reference to jquery, then check the browser console and see if there's any error when running the site
– arieljuod
Nov 22 '18 at 1:36