relatively new node.js, trying js object angular2 node.js route i'm getting standard "unexpected token blah blah @ index 0" native object parser.
the object gets node factory fine fails when posting route.
this json being sent route:
{"sqlserverhostname":"minint-mt0dkdt","sqlserverdbname":"contosoretaildw","sqlserverusername":"svc_sql_d3","sqlserverpassword":"inspur123#@!","storedprocedurename":"[dbo].[d3test]"}
this error i'm receiving in dev console.
angular2.dev.js:23083 exception: syntaxerror: unexpected token s in json @ position 0browserdomadapter.logerror @ angular2.dev.js:23083browserdomadapter.loggroup @ angular2.dev.js:23094exceptionhandler.call @ angular2.dev.js:1185(anonymous function) @ angular2.dev.js:12591ngzone._notifyonerror @ angular2.dev.js:13635onerror @ angular2.dev.js:13539zone.run @ angular2-polyfills.js:1247(anonymous function) @ angular2.dev.js:13558zoneboundfn @ angular2-polyfills.js:1220 angular2.dev.js:23083 stacktrace:browserdomadapter.logerror @ angular2.dev.js:23083exceptionhandler.call @ angular2.dev.js:1187(anonymous function) @ angular2.dev.js:12591ngzone._notifyonerror @ angular2.dev.js:13635onerror @ angular2.dev.js:13539zone.run @ angular2-polyfills.js:1247(anonymous function) @ angular2.dev.js:13558zoneboundfn @ angular2-polyfills.js:1220 angular2.dev.js:23083 syntaxerror: unexpected token s in json @ position 0 @ object.parse (native) @ xmlhttprequest.req.onload [as _onload] (http://localhost:1557/app/services/xhr-factory.service.js:17:33) @ zone.run (http://localhost:1557/node_modules/angular2/bundles/angular2-polyfills.js:1243:24) @ zone.run (http://localhost:1557/node_modules/angular2/bundles/angular2.dev.js:13558:32) @ xmlhttprequest.zoneboundfn (http://localhost:1557/node_modules/angular2/bundles/angular2-polyfills.js:1220:26)
-----async gap----- error @ _getstacktracewithuncaughterror (http://localhost:1557/node_modules/angular2/bundles/angular2-polyfills.js:2244:29) @ zone.fork (http://localhost:1557/node_modules/angular2/bundles/angular2-polyfills.js:2293:47) @ zone.bind (http://localhost:1557/node_modules/angular2/bundles/angular2-polyfills.js:1218:53) @ xmlhttprequest.obj.addeventlistener (http://localhost:1557/node_modules/angular2/bundles/angular2-polyfills.js:1503:95) @ xmlhttprequest.desc.set [as onload] (http://localhost:1557/node_modules/angular2/bundles/angular2-polyfills.js:1449:19) @ eval (http://localhost:1557/app/services/xhr-factory.service.js:11:24) @ lib$es6$promise$$internal$$initializepromise (http://localhost:1557/node_modules/angular2/bundles/angular2-polyfills.js:515:10) @ new lib$es6$promise$promise$$promise (http://localhost:1557/node_modules/angular2/bundles/angular2-polyfills.js:806:10) @ _sendrequest (http://localhost:1557/app/services/xhr-factory.service.js:7:16) @ object.post (http://localhost:1557/app/services/xhr-factory.service.js:39:28)
-----async gap----- error @ _getstacktracewithuncaughterror (http://localhost:1557/node_modules/angular2/bundles/angular2-polyfills.js:2244:29) @ zone.fork (http://localhost:1557/node_modules/angular2/bundles/angular2-polyfills.js:2293:47) @ arguments.(anonymous function) (http://localhost:1557/node_modules/angular2/bundles/angular2-polyfills.js:1671:82)
-----async gap----- error @ _getstacktracewithuncaughterror (http://localhost:1557/node_modules/angular2/bundles/angular2-polyfills.js:2244:29) @ zone.fork (http://localhost:1557/node_modules/angular2/bundles/angular2-polyfills.js:2293:47) @ ngzone._createinnerzone (http://localhost:1557/node_modules/angular2/bundles/angular2.dev.js:13546:39) @ new ngzone (http://localhost:1557/node_modules/angular2/bundles/angular2.dev.js:13412:32) @ createngzone (http://localhost:1557/node_modules/angular2/bundles/angular2.dev.js:12475:12) @ platformref_.application (http://localhost:1557/node_modules/angular2/bundles/angular2.dev.js:12550:31) @ object.bootstrap (http://localhost:1557/node_modules/angular2/bundles/angular2.dev.js:24805:64) @ execute (http://localhost:1557/app/boot.js:14:23) @ ensureevaluated (http://localhost:1557/node_modules/systemjs/dist/system.src.js:3186:26) @ object.execute (http://localhost:1557/node_modules/systemjs/dist/system.src.js:3304:13)browserdomadapter.logerror @ angular2.dev.js:23083exceptionhandler.call @ angular2.dev.js:1188(anonymous function) @ angular2.dev.js:12591ngzone._notifyonerror @ angular2.dev.js:13635onerror @ angular2.dev.js:13539zone.run @ angular2-polyfills.js:1247(anonymous function) @ angular2.dev.js:13558zoneboundfn @ angular2-polyfills.js:1220 angular2.dev.js:1206 uncaught syntaxerror: unexpected token s in json @ position 0req.onload @ xhr-factory.service.ts:28zone.run @ angular2-polyfills.js:1243(anonymous function) @ angular2.dev.js:13558zoneboundfn @ angular2-polyfills.js:1220
here angular2 component calls factory
import {component} 'angular2/core'; import {wizardsteponecomponent} './wizardstepone.component' import {wizardsteptwocomponent} './wizardsteptwo.component' import {wizardstepthreecomponent} './wizardstepthree.component' import {configurationdata} '../classes/configurationdata' import {report} '../classes/report' import {charttype} '../classes/charttype' import {wizardfactory} '../services/wizardfactory.service' @component({ selector: 'wizardmain', templateurl: '../../partials/_wizardmain.html', directives: [wizardsteponecomponent , wizardsteptwocomponent , wizardstepthreecomponent], providers: [report, charttype] }) export class wizardmaincomponent{ configurationdata: configurationdata; report: report; charttype: charttype; step1show:boolean; step2show:boolean; step3show:boolean; step4show:boolean; configmainshow:boolean; configsqlservershow:boolean; configmysqlshow:boolean; confighadoopshow:boolean; confignosqlshow:boolean; constructor(public _report: report ,public _charttype: charttype){ this.report = _report; this.charttype = _charttype; this.hideall(); this.loadstep(1); } hideall(){ this.step1show = false; this.step2show = false; this.step3show = false; this.step4show = false; this.configmainshow = false; this.configsqlservershow = false; this.configmysqlshow = false; this.confighadoopshow = false; this.confignosqlshow = false; } loadadminpanel(){ } loadmainpanel(){ } loadstep(stepnumber){ switch(stepnumber) { case 1: { this.step1show = true; this.step2show = false; this.step3show = false; this.step4show = false; this.configmainshow = false; this.configsqlservershow = false; this.configmysqlshow = false; this.confighadoopshow = false; this.confignosqlshow = false; break; } case 2: { this.step1show = false; this.step2show = true; this.step3show = false; this.step4show = false; this.configmainshow = false; this.configsqlservershow = false; this.configmysqlshow = false; this.confighadoopshow = false; this.confignosqlshow = false; break; } case 3: { this.step1show = false; this.step2show = false; this.step3show = true; this.step4show = false; this.configmainshow = false; this.configsqlservershow = false; this.configmysqlshow = false; this.confighadoopshow = false; this.confignosqlshow = false; break; } case 4: { this.step1show = false; this.step2show = false; this.step3show = false; this.step4show = true; this.configmainshow = false; this.configsqlservershow = false; this.configmysqlshow = false; this.confighadoopshow = false; this.confignosqlshow = false; break; } } } setconfigurationdata(configdata: configurationdata){ this.configurationdata = configdata; } setreportname(reportname: string){ this.report.reportname = reportname; this.loadstep(2); } setcharttype(charttypeid: number){ this.charttype.charttypeid = charttypeid; wizardfactory.getcolumnproperties(this.configurationdata).then((data) => { console.log("sql server response: " + data); }); this.loadstep(3); } setxaxis(xaxis: string){ this.configurationdata.xaxis = xaxis; } setyaxis(yaxis: string){ this.configurationdata.yaxis = yaxis; this.loadstep(4); } }
it gets factory fine here:
import {$http} './xhr-factory.service'; import {configurationdata} '../classes/configurationdata'; export const wizardfactory = { getcolumnproperties: function (currentconfig) { console.log("current config in factory: " + json.stringify(currentconfig)); return $http.post('/api/getcolumnproperties', currentconfig); } }
and xhr handler:
export const $http = { get: function(url: string) { return _sendrequest(url, null, 'get'); }, post: function(url: string, payload: any){ return _sendrequest(url, payload, 'post'); }, put: function(url: string, payload: any){ return _sendrequest(url, payload, 'put'); }, delete: function(url: string, payload: any){ return _sendrequest(url, null, 'delete'); } } function _sendrequest(url: string, payload: any, type: string): promise<json> { return new promise(function(resolve, reject) { var req = new xmlhttprequest(); req.open(type, url); req.setrequestheader("content-type", "application/json;charset=utf-8"); req.onload = function() { if (req.status == 200) { console.log("resolved"); resolve(json.parse(req.response)); } else { reject(json.parse(req.response)); } }; req.onerror = function() { reject(json.parse(req.response)); }; if (payload) { req.send(json.stringify(payload)); } else { req.send(null); } }); }
but not route have defined; i've manipulated 100 times try , syntax right:
var express = require('express'); var wizardrouter = express.router(); var sql = require('mssql'); var sqlreturndefinitionquery = "set no_browsetable on; \ set fmtonly on; \ exec {0}; \ set fmtonly off; \ set no_browsetable off"; /*get stored procedure schema*/ wizardrouter.post('/getcolumnproperties', function (req, res, next) { console.log("in router"); _currentconfig = json.parse(req.params.currentconfig); console.log("current config in router: " + req.params.currentconfig); var config = { user: _currentconfig.sqlserverusername, password: _currentconfig.sqlserverpassword, server: _currentconfig.sqlserverhostname, database: _currentconfig.sqlserverdbname }; var finalreturndefinitionquery = sqlreturndefinitionquery.replace("{0}", _currentconfig.storedprocedurename); sql.connect(config, function () { if(err) console.log(err); var request = new sql.request(); request.query(finalreturndefinitionquery, function(err, recordset){ if(err) console.log(err); res.send(recordset); }); }); }); module.exports = wizardrouter;
and here node server file:
var express = require('express'); var path = require('path'); var logger = require('morgan'); var cookieparser = require('cookie-parser'); var bodyparser = require('body-parser'); var index = require('./routes/index'); var wizard = require('./routes/wizard'); var app = express(); // view engine setup app.set('/', path.join(__dirname, 'partials')); app.set('view engine', 'ejs'); app.engine('html', require('ejs').renderfile); app.use('/js', express.static(__dirname + '/js')); app.use('/app', express.static(__dirname + '/app')); app.use('/content', express.static(__dirname + '/content')); app.use('/node_modules', express.static(path.join(__dirname, '/node_modules'))); app.use('/partials', express.static(path.join(__dirname, '/partials'))); app.use(logger('dev')); app.use(bodyparser.json()); app.use(bodyparser.urlencoded({ extended: false })); app.use(cookieparser()); app.use(express.static(path.join(__dirname, 'public'))); app.use('/', index); app.use('/api/', wizard); // catch 404 , forward error handler app.use(function (req, res, next) { var err = new error('not found'); err.status = 404; next(err); }); var server = app.listen(1557, function () { var host = 'localhost'; var port = server.address().port; console.log('app listening @ http://%s:%s', host, port); }); module.exports = app;
any appreciated; driving me nuts.
Comments
Post a Comment