我想使用Magic Suggest在我的rails應用程序中使用自動完成工作。魔術建議返回郵政404錯誤
我認爲這是一個正確的問題:我如何讓MagicSuggest抓住我給它的URL的JSON?
這是錯誤控制檯將返回當我鍵入字母:
POST http://localhost:3000/search_foods 404 (Not Found) jquery.js:8706
Uncaught Could not reach server
這裏是神奇的建議代碼:
input.magicSuggest({
data: "/foods/search/",
placeholder: "Search Foods...",
valueField:'idFood',
displayField:'foodName'
});
路線
resources :search_foods
控制器和動作
class SearchFoodsController < ApplicationController
def index
render json: %['Crack', 'Cocain', 'Gorilla Test', 'Horse Test']
end
end
當我訪問/ search_foods URL直接我得到
'Crack', 'Cocain', 'Gorilla Test', 'Horse Test'
因爲我的代碼是專門做。
我認爲這個問題是在MagicSuggest,默認情況下,發送POST請求,雖然我不知道這是完全相關:
You can pass the url from which the component will fetch its JSON data.Data will be fetched
* using a POST ajax request that will * include the entered text as 'query' parameter. The results
* fetched from the server can be:
* - an array of JSON objects (ex: [{id:...,name:...},{...}])
* - a string containing an array of JSON objects ready to be parsed (ex: "[{id:...,name:...},{...}]")
* - a JSON object whose data will be contained in the results property
* (ex: {results: [{id:...,name:...},{...}]
whay port no。 3000? –
它的意義是什麼?大聲笑我不知道,否則。這是我的機器上的默認設置。 –
當你說你直接訪問url時,你是否暗示你在瀏覽器中輸入http:// localhost:3000/search_foods並得到結果? –