Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.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 如何访问wixdb-Blog帖子_Javascript_Node.js_Angularjs_Velo - Fatal编程技术网

Javascript 如何访问wixdb-Blog帖子

Javascript 如何访问wixdb-Blog帖子,javascript,node.js,angularjs,velo,Javascript,Node.js,Angularjs,Velo,所以现在我有一个主页,是用html制作的。 我想添加一些div,显示我在WIX页面上发布的最新博客 <div layout="row" layout-align="center center"> <md-card flex="60" class="pad-md md-body-1 border-1" md-colors="{&quot;borderColor&quot

所以现在我有一个主页,是用html制作的。 我想添加一些div,显示我在WIX页面上发布的最新博客

<div layout="row" layout-align="center center">
   <md-card flex="60" class="pad-md md-body-1 border-1" md-colors="{&quot;borderColor&quot;: &quot;epprimary1-500&quot;, &quot;color&quot;: &quot;epsecondary6&quot;}">
      {{blog headline}}
      <a href="{{blog link}}">Open Blog<md-icon>open_in_new</md-icon></a>
   </md-card>
</div>

{{博客标题}
在Wix平台上,我知道他们将数据存储在所谓的数据集中的位置:


现在我需要知道如何从我的其他网站访问这些数据。

我终于找到了答案

您可以通过http请求获取所需的数据。 因此,首先,您需要在Wix的后端文件夹中添加一个javascript,并将其命名为“http functions.js”,删除其内容并添加以下代码

注意:get_blogEntry()是方法。函数名()

Blog/Posts是我使用的数据库,你可以使用wix上的任何数据库

import {ok, notFound, serverError} from 'wix-http-functions';
import wixData from 'wix-data';
export function get_blogEntry() {
  let options = {
    "headers": {
    "Content-Type": "application/json",
    "Access-Control-Allow-Origin": "*"
    }
  };
// query a collection to find matching items
return wixData.query("Blog/Posts")
.find()
.then( (results) => {
  // matching items were found
  if(results.items.length > 0) {
    let itemOne = results.items[0];
    let itemTwo = results.items[1];

    options.body = {
        "blogOneTitle": itemOne.title,
        "blogOneUrl": "https://etaplus.energy" + itemOne.postPageUrl,
        "blogTwoTitle": itemTwo.title,
        "blogTwoUrl": "https://etaplus.energy" + itemTwo.postPageUrl
    }
    return ok(options);
  }
})
// something went wrong
.catch( (error) => {
  options.body = {
    "error": error
  };
  return serverError(options);
} );
}
在后端添加此代码后,您可以通过以下URL访问数据:

"https://YOURWEBSITEURL/_functions/blogEntry或您的函数名是什么