2014-09-05 39 views
-1

我有一個視圖。在這個視圖中,我想與AJAX分成4個不同的東西。我有2個人在工作。當我添加第三個(與其他人做相同的方法)前2停止工作。要粘貼一些代碼讓你們明白。Ruby on Rails - js在js.erb文件上停止工作

爲2個paginations使用AJAX工作的視圖:

<div id="ofertas"><%= render "ofertas_ajax" %></div> 

這使它在普通的循環部分通過項的總彙和將分頁鏈接。一切都好。

正在工作,另一個是這樣的:

<div id="historico"><%= render "historico_ajax" %></div> 

此呈現的部分,正如在另一個的上面。

我對這些2的application.js:

$(document).on("click","#ofertas .pagination a",function(e){ 
    e.preventDefault(); 
    $.getScript(this.href); 
}); 

$(document).on("click","#historico .pagination a", function(e){ 
    e.preventDefault(); 
    $.getScript(this.href); 
}); 

home.js.erb,因爲所有這些div都在home.html.erb視圖

$("#ofertas").html("<%= escape_javascript(render("ofertas_ajax")) %>"); 

$("#historico").html("<%= escape_javascript(render("historico_ajax")) %>"); 

OK - 所以這個工作得很好。至少測試它,我沒有看到任何問題,並且使用AJAX正確分頁。

我加入這個div爲第三分頁:

<div id="candidaturass"><%= render "candidaturaspag" %></div> 

再次呈現一個正常部分與正常循環,正確的將分頁鏈接

我說這application.js

$(document).on("click","#candidaturass .pagination a",function(e){ 
    e.preventDefault(); 
    $.getScript(this.href); 
}); 

再次與其他類似。當然,我在home.js.erb文件添加此:

$("#candidaturass").html("<%= escape_javascript(render("candidaturaspag")) %>"); 

現在所有的paginations不起作用。我添加這行後。不知何故,我覺得我的home.js.erb文件不應該是這樣的:

$("#ofertas").html("<%= escape_javascript(render("ofertas_ajax")) %>"); 

$("#historico").html("<%= escape_javascript(render("historico_ajax")) %>"); 

$("#candidaturass").html("<%= escape_javascript(render("candidaturaspag")) %>"); 

但隨後再次我真的不知道爲什麼它不工作。如果我的文件被正確編碼。

有人可以幫忙嗎?

+0

提示:如果您使用瀏覽器的開發人員工具,請轉到網絡選項卡,單擊頁面上的一個Ajax鏈接,然後複製網絡選項卡中的響應並將其粘貼到控制檯中,它應該會告訴您關於腳本導致的任何錯誤(從服務器檢索的腳本不顯示錯誤當jQuery'eval's他們)。我不確定爲什麼你對同一模板中的所有3個單獨鏈接都有迴應,但它們是不是應該位於3個不同的模板中(並且可能由3個不同的動作渲染?),否則每個鏈接都會執行完全一樣的東西。 – Inkling 2014-09-05 12:34:02

+0

我剛剛得到500內部服務器錯誤 – Lokuzt 2014-09-16 08:39:19

+0

如果您收到500內部服務器錯誤,請查看您的日誌文件。其中一個部分可能存在拼寫錯誤或其他編碼錯誤。 – Josh 2014-09-16 11:59:26

回答

1

試試這個......在js.erb中渲染時要小心......報價應採取照顧: -

儘量遵循這樣的: -

##adding single quotes 
$("#ofertas").html("<%= escape_javascript(render('ofertas_ajax')) %>"); 

$("#historico").html("<%= escape_javascript(render('historico_ajax')) %>"); 

$("#candidaturass").html("<%= escape_javascript(render('candidaturaspag')) %>"); 

以上的諧音,如果他們是reqular諧音別人喲必須明確指定用戶/ _partial_name或別的東西,只會工作,你想要

相關問題