Bee*_*gie 2 ajax ruby-on-rails ruby-on-rails-5
Uncaught SyntaxError: Unexpected token <我在通过 js 进行部分渲染时遇到错误。该部分仅包含一个表。
正在调用部分,但浏览器控制台中的错误消息将<表标记的第一个显示为意外标记。
<table class='table table-sm'> # <- this line errors
<thead>
<tr>
<th>Part #</th>
<th>Description</th>
<th>Qty</th>
</tr>
</thead>
<tbody>
<tr>
<td>SCS-#10-24X.375-BLK</td>
<td>Countersunk screw, #10-24 X .375, Black oxide</td>
<td>2.0</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
_check_it.html.haml
- if @part.part_structures == 0
No components
- else
%table.table.table-sm
%thead
%tr
%th Part #
%th Description
%th Qty
%tbody
- @part.part_structures.each do |ps|
%tr
%td= ps.component.partNo
%td= ps.component.description
%td= ps.qty
Run Code Online (Sandbox Code Playgroud)
check_it.js.erb
$("#that_one").replace("<%= j render(partial: 'check_it') %>");
Run Code Online (Sandbox Code Playgroud)
零件控制器.rb
def check_it
respond_to do |format|
format.js {render partial: 'check_it', :content_type => 'text/html', part: @part}
end
end
Run Code Online (Sandbox Code Playgroud)
为什么 JS 控制台中 table 标签的开头会出现部分错误?
如果check_it.js.erb文件位于同一文件夹中,则无需从控制器渲染。只要方法名称相同,它就会自动执行。
# parts_controller.rb
def check_it
#@part is already class instance variable. no need also
respond_to do |format|
format.js{}
end
end
# parts/check_it.js.erb
console.log("<%= @part %>")
$("#that_one").replace("<%= j render(partial: 'check_it') %>");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5343 次 |
| 最近记录: |