我的变量"整体"未定义。
getStudents.js
var http = require('http');
module.exports = {
'sendResults': function(){
http.get(' http://gs-class.com/nodejs/students.php', function(res){
var whole = '';
res.on('data',function(chunk){
whole+=chunk;
});
res.on('end', function(){
return whole;
});
});
}
}
studWrite.js
var getStudents = require('./getStudents');
var fs = require('fs');
var results = getStudents.sendResults();
console.log(results);
当我运行程序studWrite.js时,我的var'整个'未定义。请帮助。
答案 0 :(得分:1)
试试这个:
<强> studWrite.js 强>
@extends('layouts.master')
@section('title', 'Inventory')
@section('main')
@parent
<?php
$thumbnails=$options[0]->thumbnails;
?>
.
.
.
<强> getStudents.js 强>
var getStudents = require('./getStudents');
var fs = require('fs');
getStudents.sendResults(function(result) {
console.log(result);
});
您需要使用异步方法(Callbacks,Promises)来解决问题。