2010-06-02 104 views
0

我使用jQuery發送Ajax請求。會發生什麼是我收到「405方法不允許」錯誤。我只是發佈一個表單,它會從表單獲取詳細信息並將其插入到數據庫中。只是通常的東西。我使用的WEBrick作爲默認的rails包。有人可以告訴我如何解決這個問題。在Rails中使用jQuery的Ajax請求

這是觸發AJAX請求)的代碼

$。員額($(本).attr( 「行動」)+ 「的.js」,$(本).serialize(,空」腳本」);

Response Headers 
Cache-Control no-cache 
Allow GET, PUT, DELETE 
Content-Type text/html; charset=utf-8 
Content-Length 9502 
Server WEBrick/1.3.1 (Ruby/1.9.1/2009-12-07) 
Date Wed, 02 Jun 2010 20:41:33 GMT 
Connection Keep-Alive 

Request Headers 
Host localhost:3000 
User-Agent Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 
Accept application/json, text/javascript, */* 
Accept-Language en-us,en;q=0.5 
Accept-Encoding gzip,deflate 
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7 
Keep-Alive 115 
Connection keep-alive 
Content-Type application/x-www-form-urlencoded; charset=UTF-8 
X-Requested-With XMLHttpRequest 
Referer http://localhost:3000/viewspot/3 
Content-Length 141 
Pragma no-cache 
Cache-Control no-cache 
+0

它看起來像你打電話錯誤的網址.. 你可以粘貼你的form_for電話嗎? – robertokl 2010-06-02 20:58:20

+0

<%form_for:Comment,comment,:url => {:action =>「add_comment」},:html => {:id =>「add_comment」,:method =>:post} do | f |%> – felix 2010-06-02 20:59:35

回答

0

爲什麼您使用非寧靜的網址來創建評論?是否可以使用休息提供的正常Create操作?我真的很推薦,它讓思考變得更容易。

如果你能做到這一點,這種方法的form_for應該做的伎倆:

<% form_for Comment.new do |f| %>