2014-03-06 92 views
1

返回的JavaScript我有這樣的軌道渲染JavaScript的觀點:執行其通過Ajax請求RoR中

$("##{@organization.id}-organization-introtext").hide(); 
$("##{@organization.id}-organization-full").append("#{escape_javascript(render @organization)}").hide().fadeIn('slow').focus(); 
通過它

,例如我得到這樣的數據:

$("#9-organization-introtext").hide(); 
$("#9-organization-full").append("<h2 id=\'magenta\'>\n Shell - Автосервис\n<\/h2>\n<div>\n Shell - Автосервис\n <br>\n <br>\n<\/div>\n<div>\n <strong>\n Контактная информация:\n <\/strong>\n <p>\n 8 (0152) 510 884\n 8 (029) 265 38 09\n <\/p>\n <p>\n <script type=\"text/javascript\" charset=\"utf-8\" src=\"//api-maps.yandex.ru/services/constructor/1.0/js/?sid=SrxOH8zh15XLRmFVDc91yCeDQr23_VUl&width=600&height=450\"><\/script>\n <\/p>\n <p>\n г.Ростов-на-Дону, ул.Василевского 1\n <\/p>\n<\/div>\n<div class=\'tags\'>\n <span>\n Метки:\n <\/span>\n автозапчасти, замена масла\n<\/div>\n").hide().fadeIn('slow').focus(); 

但在瀏覽器這個腳本沒有執行,爲什麼?如何運行它?並顯示這個yandex.map?

回答

0

將您的文件的head部分的Javascript代碼和@organization拆分爲Javascript代碼和HTML代碼並將其添加到文檔的head部分。

var script = document.createElement('script'); 
script.type = 'text/javascript'; 
script.text = "#{{escape_javascript(render @organization_javascript)}"; 
$("head").append(script); 

來源 - Can't append <script> element

+0

不明白你......這是導軌和Ajax代碼... – brabertaser19

+0

它僅執行的onclick鏈接和頁面不重裝 – brabertaser19

+0

是上面的代碼可以用作Javascript代碼 – emaillenin