簡體   English   中英

jquery $.get 成功回調不工作

[英]jquery $.get success callback not working

盡管檢查了 browser.network(xhr) 並看到數據從 api 成功返回,但我無法訪問我的查詢結果。但我什至無法 console.log 返回的數據。 不確定發生了什么。

這是我的代碼:

 // const url='/../../_public/api/news.php'; // does not work const url='https://jsonplaceholder.typicode.com/users/3' // works let getHandle = () => { return new Promise(function (resolve){ $.get(url, {endpoint: 'titles', param: 'titles'}, (response) => { console.log(response); resolve(response); }) }) } getHandle().then((res) => { console.log(res); })
 <script src="https://code.jquery.com/jquery-3.6.3.min.js"></script>

問題是您的api url ,您需要使用 PHP 后端啟動本地開發服務器並將 url 更改為類似'/api/news.php'

// 我用 json 占位符 API 測試了你的代碼,它有效

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM