gpt4 book ai didi

angularjs - 净: ERR_CONNECTION_CLOSED

转载 作者:太空宇宙 更新时间:2023-11-04 01:51:13 26 4
gpt4 key购买 nike

嗨,我在 Chrome 中遇到了一个问题。我不知道这是我的代码错误还是chrome错误。错误是

加载资源失败:net::ERR_CONNECTION_CLOSED

我的QSTNURLconst app = angular.module('myapp',["ngRoute"]); app.value("QSTNURL","https://localhost:12345/api/insertQuestion");

我的客户端的controller.js是

app.controller('myctrl',function($scope,userFactory,QSTNURL){
$scope.pushData = function(){
var qstn = $scope.qstn;
var opt1 = $scope.opt1;
var opt2 = $scope.opt2;
var opt3 = $scope.opt3;
var opt4 = $scope.opt4;
var ans = $scope.ans;
const qstnObject = {
"qstn":qstn,
"opt1":opt1,
"opt2":opt2,
"opt3":opt3,
"opt4":opt4,
"ans":ans
}
console.log('doAjax');
var promise = userFactory.doAjax(QSTNURL,qstnObject);
promise.then(function(response){
$scope.data = response;
},function(error){
$scope.error = error;
});
}

});

我对服务器的 ajax 调用是

app.factory("userFactory",function($http,$q){
var userObject = {
doAjax(QSTNURL,qstnObject){
console.log('doAjax()');
var defer = $q.defer();
$http.get(QSTNURL,qstnObject).then(function(response){
defer.resolve(response);
console.log("doAjax 2");
},function(error){
defer.reject(error);
});
return defer.promise;

}
};
return userObject;
});

服务器.js

const express = require("express");
var expressSession = require('express-session');
const app = express();
var path = require("path");
var bodyParser = require('body-parser');
const userRoutes = require("./routes/userroutes");
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

app.use(express.static(path.join(__dirname, 'public')));
app.use(expressSession({secret: 'mySecretKey'}));

app.use('/api',userRoutes);

app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());


app.use('/',userRoutes);
app.listen(12345,()=>{
console.log("Server Start...");
});

我的所有静态文件(例如:- 用于制作 SPA 的所有 js 文件,例如 app.js、 Controller 、facotry 等)都位于公共(public)文件夹中, View 部分位于 View 文件夹中

我的路线代码是

router.get('/insertQuestion',(req,response)=>{
console.log("insertQuestion");
var qstn = req.body.qstn;
var opt1 = req.body.opt1;
var opt2 = req.body.opt2;
var opt3 = req.body.opt3;
var opt4 = req.body.opt4;
var ans = req.body.ans;
var qstnObject = new Insert(qstn,opt1,opt2,opt3,opt4,ans);
userOperation.insertQuestion(qstnObject,response,req);
response.json("question inserted");
});

最佳答案

仅当您没有在 12345 端口上运行服务器时,才会发生此错误。

您正在调用https://localhost:12345/dashboard/insertQuestion。因此,您还应该考虑您正在使用 https 方案,因此请确保您的服务器支持 https 方案并且端口正确。

如果您尚未将 Node 应用程序/服务器应用程序配置为在 https 上运行,则只需替换

https://localhost:12345/dashboard/insertQuestion

http://localhost:12345/dashboard/insertQuestion

关于angularjs - 净: ERR_CONNECTION_CLOSED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49627604/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com