简体   繁体   English

Remotipart JS不执行

[英]Remotipart JS Not Executing

I have a form that needs to submit a .csv file to the server and then append the words in it to a textarea in my page. 我有一个需要将.csv文件提交到服务器,然后将其中的单词附加到页面中的textarea的表单。 I am using Remotipart to upload the .csv using AJAX but I cannot get the javascript in the server response to execute. 我正在使用Remotipart使用AJAX上传.csv,但无法在服务器响应中获取javascript以执行。 Here are the relevant parts of my code: 这是我的代码的相关部分:

The Form: 表格:

=form_tag(upload_canvas_words_admin_page_widget_widget_instance_path(widget.page, widget),:method=>'post',:remote=>true,:multipart=>true,:class=>"upload_words_csv") do
        = label_tag "Upload File"
        = file_field_tag "file"
        = submit_tag "Upload"

The Controller: 控制器:

def upload_canvas_words
    @csv_text = params[:file].read
end

The .js.haml file: .js.haml文件:

= remotipart_response do
    - if remotipart_submitted?
        alert('#{@csv_text}');
        alert('!');
    - else 
        alert('WHYYYYY?');

When I look at the response I see the javascript being wrapped in a bunch of html, which I assume has something to do with the iFrame transport. 当我查看响应时,我看到javascript被包裹在一堆html中,我认为这与iFrame传输有关。 But the javascript never actually executes. 但是javascript从未真正执行过。

Refer this issue. 请参阅此问题。 And try to follow the solution given here. 并尝试遵循此处给出的解决方案。

https://github.com/JangoSteve/remotipart/issues/89 https://github.com/JangoSteve/remotipart/issues/89

So what happens is that reponse arrives to the browser with html entity (like " ) inside the textarea. 因此,发生的事情是响应以文本区域内的html实体(如" )到达浏览器。 When the js code for evaluation is extracted the html entities are replaced by theirs respective characters (like " to '). 当提取用于评估的js代码时,html实体将替换为它们各自的字符(例如“到”)。

That's a characteristic of a textarea. 这是文本区域的特征。 So it doesn't get executed 所以它不会被执行

在表单中添加data: {type: :script}应该可以解决

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM