我正在編寫一個簡單的實時搜索塊插件。我通過 API 訪問外部網站的資源,并顯示與用戶在鍵入時搜索的內容相匹配的結果。我正計劃編寫一個可以執行此操作的 Web 服務。我將用戶輸入作為 ajax.call 中的參數之一傳遞,然后我的 Web 服務函數將返回建議的結果。我想知道是否有必要使用網絡服務,因為我沒有從 Moodle 數據庫檢索或返回任何數據,我不想存儲建議而只顯示它們?,F在我正在使用 XMLHttpRequest 在我的插件中調用一個內部 php 文件,該文件通過 api 連接并返回結果,但我想知道是否有推薦的方法來做到這一點。//the ajax callajax.call([{ methodname: 'block_xxxx_loadpages', args: {userinput: userinput},}])// the webservice functionclass block_xxxx_external extends external_api { //parameters public static function loadpages() { return new external_function_parameters ( array('userinput' => new external_value(PARAM_TEXT, 'the user input')) ); } //the function public static function loadpages($userinput = 'userinput') { //parameter validation $params = self::validate_parameters(self::hello_world_parameters(), array('userinput' => $userinput)); //connect to api and return the result page matching the userinput return $result; } public static function loadpages_returns() { return new external_value(PARM_TEXT, 'the result') }}
1 回答

蠱毒傳說
TA貢獻1895條經驗 獲得超3個贊
除非您很好地處理了異常和功能,否則對于moodle 中的每個ajax 調用都不需要Web 服務。您可以使用常規 XML HttpRequest 來獲取數據。
- 1 回答
- 0 關注
- 134 瀏覽
添加回答
舉報
0/150
提交
取消