我是編程和新項目的新手,我正在使用Parse.com Cloud Code和Express構建一個Web應用程序。該結構是這樣的:
基於URL參數顯示動態網頁內容(Parse Cloud,Express,ejs)
- app.js(快遞相關代碼)
- 的意見/ hello.ejs(模板)
- main.js(雲功能)
我還有一個iOS應用可以在Facebook上發佈鏈接,如下所示:myapp.parseapp.com/hello?objectid
。當Facebook用戶點擊該鏈接並重定向到網絡應用程序時,網絡應用程序將自動根據所提供的objectid
模板res.render
。然後使用objectid
從Parse類使用Parse.Query獲取一些數據,這些數據將顯示在頁面上,但我的障礙不在於Parse.Query。
要檢查是否objectid
成功地通過服務器所捕獲,我嘗試下面的代碼來呈現模板,並插入objectid
到佔位符text
變量,但put objectid here
當頁面加載不改變所提供的objectid
。任何人都可以告訴我哪裏出了問題,或者如果我應該用另一種方法做到這一點?
hello.ejs (template):
<!DOCTYPE html>
<html>
<head>
<title>My Web App</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
$.post('/hello', {oid: window.location.toString().split("?")[1]});
</script>
</head>
<body>
<p><%= text %></p>
</body>
</html>
app.js (express):
// Initialize Express in Cloud Code.
var express = require('express');
var app = express();
// Global app configuration section
app.set('views', 'cloud/views'); // Specify the folder to find templates
app.set('view engine', 'ejs'); // Set the template engine
app.use(express.bodyParser()); // Middleware for reading request body
// Render view
app.get('/hello', function(req, res) {
res.render('hello', { text: 'put objectid here' });
});
app.post('/hello', function(req, res) {
res.render('hello', { text: req.body.oid });
});
app.listen();
我在另一篇文章中找到了解決方案:http://stackoverflow.com/questions/20089582/how-to-get-url-parameter-in-express-node-js – Pork