- Сообщений: 33
- Спасибо получено: 1
Это форк Vinaora Nivo Slider, пришлось переименовать, в силу требования JED. Даже старую версию качать можно было только с варезных сайтов, нашпигованную троянами. Зачем оно такое, согласитесь.
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.
rails new ajax_my_test
cd ajax_my_test
rails generate scaffold Staff name:string profession:string
rake db:migrate
rails s
//= require jquery
//= require jquery
//= require rails-ujs
//= require turbolinks
//= require_tree .
Rails 5.1+
The Rails JavaScript helpers has been rewritten in a new gem called rails-ujs and they use vanilla JavaScript, so jQuery is not a dependency of Rails anymore. Since bootstrap relies on it, install it with bin/yarn add jquery and add //= require jquery to application.js.
# Use jquery as the JavaScript library
gem 'jquery-rails'
app/views/staffs
$('.delete_staff').bind('ajax:success', function(){
$(this).closest('tr').fadeOut();
});
app/view/staffs/index.html.erb
<td><%= link_to 'Destroy', staff, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<td><%= link_to 'Destroy', staff, method: :delete, data: { confirm: 'Are you sure?' },
:remote => true, :class => 'delete_staff'%></td>
def destroy
@staff.destroy
respond_to do |format|
format.html { redirect_to staffs_url, notice: 'Staff was successfully destroyed.' }
format.json { head :no_content }
end
end
def destroy
@staff.destroy
respond_to do |format|
format.html { redirect_to staffs_url, notice: 'Staff was successfully destroyed.' }
format.json { head :no_content }
format.js { render :layout => false}
end
end
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.
Aleksej пишет: Еще один пример работы формы на ajax .
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.
<button id="btnSubmit" type="submit" class="btn btn-default">Go ahead</button>
<script type="text/javascript" language="javascript">
function call() {
$('#btnSubmit').prop('disabled', true);
var msg = $('#form_name').serialize();
$.ajax({
type: 'GET',
url: '/index.html',
data: msg,
success: function(data) {
$('#btnSubmit').prop('disabled', false),
alert('ГОтово');
},
error: function(xhr, str){
$('#btnSubmit').prop('disabled', false),
alert('Что-то пошло не так: ' + xhr.responseCode);
}
});
}
</script>
<button onclick="style.display='none'">Go ahead</button>
Пожалуйста Войти или Регистрация, чтобы присоединиться к беседе.