Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 基于URL参数显示动态网页内容(解析云、Express、ejs)_Javascript_Jquery_Ajax_Express_Parse Platform - Fatal编程技术网

Javascript 基于URL参数显示动态网页内容(解析云、Express、ejs)

Javascript 基于URL参数显示动态网页内容(解析云、Express、ejs),javascript,jquery,ajax,express,parse-platform,Javascript,Jquery,Ajax,Express,Parse Platform,我是编程新手,对于这个项目,我正在使用Parse.com云代码和Express构建一个web应用程序。结构如下所示: app.js(快递相关代码) 视图/hello.ejs(模板) main.js(云函数) 我还有一个iOS应用程序,可以在Facebook上发布如下链接:myapp.parseapp.com/hello?objectid。当Facebook用户单击该链接并被重定向到web应用程序时,web应用程序将根据提供的objectid自动呈现模板。然后使用objectid从使用Pars

我是编程新手,对于这个项目,我正在使用Parse.com云代码和Express构建一个web应用程序。结构如下所示:

  • app.js(快递相关代码)
  • 视图/hello.ejs(模板)
  • main.js(云函数)
我还有一个iOS应用程序,可以在Facebook上发布如下链接:
myapp.parseapp.com/hello?objectid
。当Facebook用户单击该链接并被重定向到web应用程序时,web应用程序将根据提供的
objectid
自动呈现模板。然后使用
objectid
从使用Parse.Query的Parse类中获取一些数据,这些数据将显示在页面上,但我的障碍不是Parse.Query

为了检查服务器是否成功捕获了
objectid
,我尝试了以下代码来呈现模板,并将
objectid
插入
text
变量的占位符中,但是加载页面时,
将objectid放入此处
不会更改为提供的
objectid
。有人能告诉我哪里出了问题,或者我是否应该用另一种方法来做吗?

hello.ejs(模板):


经过进一步研究,我发现了这篇文章:。决定试一试,结果成功了!以下是解决方案。

URL更改为:
myapp.parseapp.com/hello?id=objectid

不再需要
中的
。最终代码如下所示:

hello.ejs(模板):


干杯

我在另一篇帖子中找到了解决方案:
<!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>
// 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();
<!DOCTYPE html>
<html>
  <head>
    <title>My Web App</title>
  </head>
  <body>
    <p><%= text %></p>
  </body>
</html>
// 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: req.param("id") });
});

app.listen();