AJAX不工作表工作、AJAX

2023-09-10 18:06:24 作者:密码里都藏着秘密

试图让我的应用程序功能更强大的通过包括阿贾克斯我的表。我用这个 http://asciicasts.com/episodes/240-search-排序分页,与阿贾克斯教程创建我的code和保持非常,非常接近的指令。

tried to make my application more functional by including ajax to my tables. I used this http://asciicasts.com/episodes/240-search-sort-paginate-with-ajax tutorial to create my code and kept very, very close to the instructions.

我使用IE8的(这可能是因为这个问题的它总是事业问题的原因)和铁路4。

I'm using IE8 (what could be the cause of the problem since its always the cause of the problem) and Rail 4.

我的的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, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, 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.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require_tree .


    $(function () {
      // Sorting and pagination links.
      $('#pimps th a, #pimps .pagination a').live('click', function () {   
        $.getScript(this.href);   
        return false;   
        });

      // Search form.
      $('#pimps_search').submit(function () {   
        $.get(this.action, $(this).serialize(), null, 'script');   
        return false;
     });   
    }) 

index.js.erb的

$('#pimps').html('<%= escape_javascript(render(:partial =>"pimps")) %>'));  

index.html.erb

<h1>Improvements: Overview</h1>

<%= form_tag pimps_path, :method => 'get', :id => "pimps_search" do %>   
  <%= hidden_field_tag :direction, params[:direction] %>   
  <%= hidden_field_tag :sort, params[:sort] %> 
  <p>   
    <%= text_field_tag :search, params[:search] %>   
    <%= submit_tag "Search", :title => nil %>   
  </p>   
<% end %>

<div id="pimps"><%= render 'pimps' %></div>  


<div class="row">
    <div class="col-md-10"><%= will_paginate @pimps %></div>
    <div class="col-md-2"><%= button_to 'New Improvement', new_pimp_path, :method => :get %></div>
</div>

我也跑轨道摹jQuery的:安装

我的布局 application.html.erb

<!DOCTYPE html>
<html lang="en">
<head>

  <title>Improvement</title>

  <%= stylesheet_link_tag    "application", media: "all", "data-turbolinks-track" => true %>
  <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
  <%= csrf_meta_tags %>
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />

  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
  <![endif]-->


</head>
<body>



<%= yield %>

</body>
</html>

有谁知道可能是什么问题就在这里?如果它的IE8,是有办法仍然集成AJAX?

Does anyone know what could be the problem here? If its IE8, is there a way to integrate AJAX nevertheless?

最诚挚的问候我的朋友们!

Best regards my friends!

推荐答案

圣钼!花了一些时间,但终于发现了问题。

Holy moly! Took some time but finally found the problem.

index.js.erb的

index.js.erb

$('#pimps').html('<%= escape_javascript(render(:partial =>"pimps")) %>'));

最后支架是太多了!它更改为:

Last bracket was too much! Changed it to:

$('#pimps').html('<%= escape_javascript(render(:partial =>"pimps")) %>');

而现在它工作正常。

And now it works fine.

也不得不增加里克斯code,因为我的jQuery的版本和冲突与turbolinks'活'不工作!

Also had to add Ricks code because 'live' doesnt work with my jquery version and conflicts with turbolinks!