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

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

nodejs + express + Ajax的get方式提交表單,可以嗎

nodejs + express + Ajax的get方式提交表單,可以嗎

慕斯709654 2019-05-31 10:02:29
nodejs + express + Ajax的get方式提交表單,可以嗎
查看完整描述

3 回答

?
慕森卡

TA貢獻1806條經驗 獲得超8個贊

componentDidMount: function() {
//ajax請求
var xmlhttp;
if(window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}else if(window.ActiveXObject) {
xmlhttp = new ActiveXObject(‘Microsoft.XMLHTTP’);
}else {
alert(‘必須提高瀏覽器版本才能瀏覽!’);
return false;
}
//回調
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4) {
if(xmlhttp.status == 304 || (xmlhttp.status >= 200 && xmlhttp.status < 300)) {
var renderMessage = JSON.parse(xmlhttp.responseText);
if(this.isMounted()){
this.setState({
data: renderMessage,
});
}
}
}
}.bind(this);
//請求
xmlhttp.open(‘post’,’/photo.list.server’,true);
xmlhttp.setRequestHeader(“Content-Type”,“application/x-www-form-urlencoded;charset=utf-8”);
xmlhttp.send(null);
}
以上是前端的代碼。
后臺其實邏輯如下:
var mongoose = require(‘mongoose’);
var PhotoList = mongoose.model(‘PhotoList’);
module.exports = function(req, res, next) {
PhotoList.find({}, function(err, docs) {
if(err) {
res.end(‘Error’);
return next();
}
res.send(JSON.stringify(docs));
});
}





查看完整回答
反對 回復 2019-06-01
?
森欄

TA貢獻1810條經驗 獲得超5個贊

其實就是使用express做后臺接口,可以看一下express的文檔?;蛘呔W上有很多express的代碼。

1

2

3

4

5

6

var express = require('express');

var app = express();

app.get('/', function (req, res) {

  res.send('Welcome');

})

app.listen(3000);

 

 




查看完整回答
反對 回復 2019-06-01
  • 3 回答
  • 0 關注
  • 494 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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