I have a code to responde format js
app = CheckAppExist.new(params[:url])
if(app.exist?)
cookies[:package_name] = app.package_name
cookies[:app_url] = app.app_url
respond_to do |format|
format.html {}
format.json {}
format.js { render :text => "200" }
end
else
respond_to do |format|
format.html {}
format.json {}
format.js { render :text => "Url or Package Name is wrong ", status: :unprocessable_entity }
end
end
Code above is work, but when i change respond text with
format.js { render :text => "200" }
to format.js { render :text => "some text here" }
It don't work. I use rails ujs to send and receive request.
When is text is a String number("200"), method .on("ajax:success",...)
is run, when text render is String method .on("ajax:error",...)
is run.
I don't understand about above error, anyone can help me. Tks.
尝试这个:
render inline: 'your text'
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.