我給$.post調用一個node.js文件的服務器的URL是什麼。我一直看到php文件的教程,但我對什麼node.js文件要調用困惑?我想將它發佈到app.js文件或路徑文件?什麼是jQuery發佈網址?
這是app.js文件的樣子:
var express = require('express')
, app = express()
, dbUserModel = require('./models/user')
, db = require('./db')
, pass = require('./config/passport')
, passport = require('passport')
, routes = require('./routes/index')
, user = require('./routes/user')
, path = require('path')
, http = require('http')
, connect = require('connect')
, mongoose = require('mongoose')
, mongoConnect = mongoose.connect('mongodb://localhost/test5');
// all environments
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.cookieParser('sabkdasdkjhakhfkahf7232ujdijaw9jok&^&^@88'));
//app.use(express.cookieSession());
app.use(express.methodOverride());
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
//use bottom for 404 error
app.use(function(req,res){
res.render('noPage.jade');
});
});
app.get('/', routes.index);
app.get('/register', user.mustBeLoggedOut, user.register);
app.post('/register', user.registerPost);
app.get('/login', user.mustBeLoggedOut, user.login);
app.post('/login', user.loginPost);
app.get('/userProfile', user.mustBeLoggedIn, user.userProfile);
app.get('/editUserProfile', user.mustBeLoggedIn, user.editUserProfile);
app.post('/editUserProfile', user.editUserProfilePost);
app.get('/loggedIn', user.mustBeLoggedIn, user.loggedIn);
app.get('/contactList', user.mustBeLoggedIn, user.contactList);
app.get('/search', user.search);
app.post('/search', user.searchPost);
app.get('/user/:id', user.user);
app.post('/addContact', user.addContactPost);
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
console.log('Users: ' + db.collections.users);
});
這是該路由的文件看起來是這樣的:(我知道在路由文件中的代碼可能無法在試圖提取用戶是正確的
$('.addContact').click(function() {
$.post('user.js',
function(data) {
$('.addContact').html(data);
}
);
if($(this).html!=='Contact Requested') {
return $(this).html('Contact Requested');
}
});
0123:.ID與該按鈕,還在進展中的工作)
exports.addContactPost = function(req, res, err) {
User.findByIdAndUpdate(req.signedCookies.userid,{
friendRequest: req.body.userid
}, function(err) {
if(err) {
console.log("post2");
return res.render('addContactError', {title: 'Weblio'});
}
});
};
這是腳本文件,試圖找出相關的網址
這是玉文件:
extends layout
block content
div
legend Search Results
div#userResults
for user in ufirstName
a(href='/user/#{user.id}')
p #{user.firstName} #{user.lastName}
button.addContact Add Contact
我已經添加了'express'標記,因爲顯然你使用'express'。 –