這裏是我們的賴斯3.2應用程序的js代碼響應更改其IDS開始 'order_order_items_attributes' 字段:
$(function(){
$(document).on('change', "[id^='order_order_items_attributes'][id$='_name']", function(){
$.post(window.location, $('form').serialize(), null, "script");
return false;
});
});
的$。後()導致錯誤:
"NetworkError: 404 Not Found - http://localhost:3000/po/orders/new?parent_record_id=4&parent_resource=ext_construction_projectx%2Fprojects&project_id=4%22"
這裏是window.location
:
如果我們更換$。員額()與$獲得(),那麼鱈魚Ë正常工作,並觸發了服務器上的Ajax響應:
$.get(window.location, $('form').serialize(), null, "script"); #works!
但是,我們必須使用$。員額(),因爲大量的數據被髮送到服務器。 jquery文檔顯示$ .get()和$ .post()具有完全相同的格式。我們在$ .post()中錯過了什麼?謝謝。
UPDATE:耙路輸出:
Routes for PurchaseOrderx::Engine:
search_order_items GET /order_items/search(.:format) purchase_orderx/order_items#search
search_results_order_items GET /order_items/search_results(.:format) purchase_orderx/order_items#search_results
stats_order_items GET /order_items/stats(.:format) purchase_orderx/order_items#stats
stats_results_order_items GET /order_items/stats_results(.:format) purchase_orderx/order_items#stats_results
order_items GET /order_items(.:format) purchase_orderx/order_items#index
POST /order_items(.:format) purchase_orderx/order_items#create
new_order_item GET /order_items/new(.:format) purchase_orderx/order_items#new
edit_order_item GET /order_items/:id/edit(.:format) purchase_orderx/order_items#edit
order_item GET /order_items/:id(.:format) purchase_orderx/order_items#show
PUT /order_items/:id(.:format) purchase_orderx/order_items#update
DELETE /order_items/:id(.:format) purchase_orderx/order_items#destroy
search_orders GET /orders/search(.:format) purchase_orderx/orders#search
search_results_orders GET /orders/search_results(.:format) purchase_orderx/orders#search_results
stats_orders GET /orders/stats(.:format) purchase_orderx/orders#stats
stats_results_orders GET /orders/stats_results(.:format) purchase_orderx/orders#stats_results
event_action_order GET /orders/:id/event_action(.:format) purchase_orderx/orders#event_action
acct_approve_order PUT /orders/:id/acct_approve(.:format) purchase_orderx/orders#acct_approve
acct_reject_order PUT /orders/:id/acct_reject(.:format) purchase_orderx/orders#acct_reject
gm_approve_order PUT /orders/:id/gm_approve(.:format) purchase_orderx/orders#gm_approve
gm_reject_order PUT /orders/:id/gm_reject(.:format) purchase_orderx/orders#gm_reject
gm_rewind_order PUT /orders/:id/gm_rewind(.:format) purchase_orderx/orders#gm_rewind
submit_order PUT /orders/:id/submit(.:format) purchase_orderx/orders#submit
list_open_process_orders GET /orders/list_open_process(.:format) purchase_orderx/orders#list_open_process
orders GET /orders(.:format) purchase_orderx/orders#index
POST /orders(.:format) purchase_orderx/orders#create
new_order GET /orders/new(.:format) purchase_orderx/orders#new
edit_order GET /orders/:id/edit(.:format) purchase_orderx/orders#edit
order GET /orders/:id(.:format) purchase_orderx/orders#show
PUT /orders/:id(.:format) purchase_orderx/orders#update
DELETE /orders/:id(.:format) purchase_orderx/orders#destroy
root / purchase_orderx/orders#index
這裏是輸出耙路線採購訂單引擎。大多數路線與問題無關,仍按原樣列出。
這裏的routes.rb:
resources :order_items do
collection do
get :search
get :search_results
get :stats
get :stats_results
end
end
resources :orders do
collection do
get :search
get :search_results
get :stats
get :stats_results
end
end
工作流相關行動在routes.rb中,便於讀取被拆除。
你嘗試發佈來創建嗎?像 - http:// localhost:3000/po/orders /創建?parent_record_id = 4&parent_resource = ext_construction_projectx%2Fprojects&project_id = 4%22「 – 2015-02-12 20:53:04
您可能沒有在routes.rb中指定路徑爲POST。我們的routes.rb看起來像? – 2015-02-12 20:54:43
這篇文章將發送表單上的用戶輸入到服務器ajax。服務器接受用戶輸入並從數據庫中檢索並在某些字段中插入表單。由於用戶可以動態地向表單添加更多字段,因此回發到服務器的數據可能非常大。這就是爲什麼我們要使用$ .post而不是$ .get。 – user938363 2015-02-13 03:34:27