我有兩個不同的項目,不知何故我必須將數據從 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));
- 1 回答
- 0 關注
- 75 瀏覽
添加回答
舉報
0/150
提交
取消