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

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

從 JSON API(從一臺服務器)獲取數據并將其顯示在 HTML 上(到另一臺服務器)

從 JSON API(從一臺服務器)獲取數據并將其顯示在 HTML 上(到另一臺服務器)

慕姐8265434 2023-09-18 15:53:09
我有兩個不同的項目,不知何故我必須將數據從 Project1 傳遞到 Project2。所以我決定將數據庫中的Project1數據作為JSON API,并使用Project2的HTML頁面來調用它。但是數據沒有成功顯示。JSON 文件如下所示:{    "data": [        {            "title": "Corporate Finance",            "responsibilities": "Responsible for financial accounting and reporting, internal controls, budgetary control, variance analysis.",            "requirements": "Candidate must possess at least a Degree in Accountancy or Professional Degree or equivalent.",            "status": "1"        },        {            "title": "Group Reporting Accountant",            "responsibilities": "We are seeking a Group accountant to take full financial responsibility for the Group Consolidation and Reporting. Reporting to the Regional Financial Controller, you will be responsible for formulati",            "requirements": "Prepare monthly financial statements for the business and to consolidate the group accounts.",            "status": "1"        }    ]}我嘗試在Project2 HTML頁面下使用AJAX來發出請求:$.ajax({        url: 'http://localhost/dbpass/api/post/read.php',        dataType: "text",        success: function(data) {            // Parse JSON file            var json = $.parseJSON(data);            //Store data into a variable            // Display             $('#results').html(json.data);        }      });并在 HTML 上顯示它:<span id="results"></span>我是新手,如有錯誤請多多包涵,謝謝!
查看完整描述

1 回答

?
炎炎設計

TA貢獻1808條經驗 獲得超4個贊

您可以使用JSON.stringify打印對象的內容。

$('#results').html(JSON.stringify(json.data, null, 4));


查看完整回答
反對 回復 2023-09-18
  • 1 回答
  • 0 關注
  • 75 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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