温温酱
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));});}