I have a button that submits a form remotely with Ajax using the rails built in helpers:
button_to 'Delete Document', [:proofreader, proofreading_job, proofread_document],
method: :delete,
remote: true,
class: "btn btn-danger btn-sm",
data: { disable_with: "Deleting document..." }
When the form is submitted to the controller I can cause an alert to show as follows:
def destroy
@proofread_document.destroy
respond_to do |format|
format.js { render js: "alert('The username to be displayed is:')"}
end
end
However when I want to render the destroy.js.erb file which has no code in it yet I get the following error in the browser:
def destroy
@proofread_document.destroy
respond_to do |format|
format.js
end
end
Uncaught SyntaxError: Unexpected token <
at processResponse (rails-ujs.self-ed0b535c2816e34ce8dee0346bd17387dffd4873cb347fa9a8b267dae6f7f41b.js?body=1:257)
at rails-ujs.self-ed0b535c2816e34ce8dee0346bd17387dffd4873cb347fa9a8b267dae6f7f41b.js?body=1:186
at XMLHttpRequest.xhr.onreadystatechange (rails-ujs.self-ed0b535c2816e34ce8dee0346bd17387dffd4873cb347fa9a8b267dae6f7f41b.js?body=1:241)
How can I fix this problem its stopped all development on this project.
the <
charecter comes from layout file. You can use layout: false
with render
.
def destroy
@proofread_document.destroy
respond_to do |format|
format.js {render layout: false}
end
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.