亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如果我不在 DB 上執行 CRUD 操作,我應該使用 Web 服務嗎?

如果我不在 DB 上執行 CRUD 操作,我應該使用 Web 服務嗎?

PHP
滄海一幻覺 2021-07-07 17:02:33
我正在編寫一個簡單的實時搜索塊插件。我通過 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 來獲取數據。


查看完整回答
反對 回復 2021-07-16
  • 1 回答
  • 0 關注
  • 134 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號