javascript
在text html模版中写js,Rails3使用text/html内容类型而不是text/javascript呈现js.erb模板...
我正在使用3.0.0.beta3構建一個新的應用程序.我只是嘗試將js.erb模板呈現給Ajax請求以執行以下操作(在publications_controller.rb中):
def get_pubmed_data
entry = Bio::PubMed.query(params[:pmid])# searches PubMed and get entry
@publication = Bio::MEDLINE.new(entry) # creates Bio::MEDLINE object from entry text
flash[:warning] = "No publication found."if @publication.title.blank? and @publication.authors.blank? and @publication.journal.blank?
respond_to do |format|
format.js
end
end
目前,我的get_pubmed_data.js.erb模板很簡單
alert('')
服務器正在響應以下內容
alert('Evidence for a herpes simplex virus-specific factor controlling the transcription of deoxypyrimidine kinase.')
不同之處在于沒有在瀏覽器中發生的,可能是因為內容類型的響應是不是如圖這里部分轉載響應頭"文/ JavaScript的""text/html的",這是完美的罰款:
Status 200
Keep-Alive timeout=5, max=100
Connection Keep-Alive
Transfer-Encoding chunked
Content-Type text/html; charset=utf-8
這是一個錯誤還是我錯過了什么?謝謝你的幫助!
總結
以上是生活随笔為你收集整理的在text html模版中写js,Rails3使用text/html内容类型而不是text/javascript呈现js.erb模板...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 苹果手机连无线网路由器怎么设置苹果手机如
- 下一篇: html网页设如何置访问密码,利用JS给