我試圖使用Express和請求調用College Score Card API。當我搜索一所特定的學校時,我收到了幾所學校的成績,但沒有收到我搜索的學校的成績。這裏是我的代碼部分:使用Express的外部API調用
var fields = '_fields=school.name,2013.aid.median_debt.completers.overall,2013.repayment.1_yr_repayment.completers,2013.earnings.10_yrs_after_entry.working_not_enrolled.mean_earnings&page=100';
var requestUrl = 'https://api.data.gov/ed/collegescorecard/v1/schools.json?api_key=' + apiKey + '&' + fields;
module.exports = function(app) {
app.get('/school', function(req, res, next) {
request(requestUrl, function (error, response, body) {
if (!error && response.statusCode == 200) {
var json = JSON.parse(body);
console.log(json);
} else {
console.log("There was an error: ") + response.statusCode;
console.log(body);
}
});
})
};
HTML:
<form action="/school" method="GET">
<input type="text" class="form-control" name="school_name" value="" id="enter_text">
<button type="submit" class="btn btn-primary" id="text-enter- button">Submit</button>
</form>
HTML: <形式行動= 「/學校」 方法= 「GET」> \t \t <按鈕類型= 「提交」 類= 「BTN BTN-主」 ID = 「文本進入─ 鍵」>提交 – user8767190
添加形式碼到您的問題使用「編輯」鏈接並修復您的格式。請了解如何在此處正確設置代碼格式,以便於閱讀。 – jfriend00
什麼是'requestUrl',它來自哪裏?現在,在你的請求中並沒有出現你使用表單值的情況,看起來你得到的結果完全取決於requestUrl是什麼。所以,基本上你沒有向我們展示代碼中最重要的部分。 – jfriend00