剛開始用node+express,使用了靜態頁面請求ajax出現問題,目前結果來看是:1.第一次請求不進入success,打印undefined;2.第二次請求開始,進入success,打印第一次請求結果;3.第三次請求打印第二次請求結果,但查看后臺傳輸值發現,傳輸過去的值沒有問題,接收的值出現問題請教這個問題怎么解決?app.js代碼是:varmysql=require('mysql');varexpress=require('express');varapp=express();varsettings=require('./build/db');app.use(express.static('./src'));//連接數據庫varconnection=mysql.createConnection(settings.db);connection.connect(function(err){if(err){console.log('[query]-:'+err);}else{console.log('[connectionconnect]succeed!');}});//查詢vararr=[];//把搜索值輸出app.get('/getname',function(req,res){varselectSQL='selectlinknamefrom`mkln_server_contract`';connection.query(selectSQL,function(err,rows){if(err)throwerror;for(vari=0;i
express中ajax請求第一次undefined后續均成功,但結果是上一次的結果而非該次請求的結果
開滿天機
2019-05-21 16:20:11