我有兩個(gè)不同的項(xiàng)目,不知何故我必須將數(shù)據(jù)從 Project1 傳遞到 Project2。所以我決定將數(shù)據(jù)庫(kù)中的Project1數(shù)據(jù)作為JSON API,并使用Project2的HTML頁(yè)面來調(diào)用它。但是數(shù)據(jù)沒有成功顯示。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頁(yè)面下使用AJAX來發(fā)出請(qǐng)求:$.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>我是新手,如有錯(cuò)誤請(qǐng)多多包涵,謝謝!
1 回答

炎炎設(shè)計(jì)
TA貢獻(xiàn)1808條經(jīng)驗(yàn) 獲得超4個(gè)贊
您可以使用JSON.stringify打印對(duì)象的內(nèi)容。
$('#results').html(JSON.stringify(json.data, null, 4));
- 1 回答
- 0 關(guān)注
- 87 瀏覽
添加回答
舉報(bào)
0/150
提交
取消