net : ERR_CONNECTION_CLOSED

hi I have been facing a problem in chrome. I don't know if it is my code fault or the chrome fault. And the error is

Failed to load resource: net::ERR_CONNECTION_CLOSED

my QSTNURL is const app = angular.module('myapp',["ngRoute"]); app.value("QSTNURL","");

my controller.js from client side is

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

And my ajax call to server is

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

server.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..."); }); 

my all the static files(like:- all js files to make SPA e.g. app.js, controller, facotry etc.) are in public folder and view part in views folder

my routes code is

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"); }); 
2

2 Answers

This error only happens if you have no server running on the 12345 port.

You are calling . So you should also consider that you are using https scheme so make sure your server supports https scheme and port is proper.

If you haven't configured your node app/server app to run on https then just replace

 

with

 
4

hey I got the answer the whole problem was in the QSTNURL. I should not have passed this URL while pass only api/insertQuestion directly to the AJAX call like this

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

I don't know why it is so. but It removed my problem

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like