Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.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 在客户端呈现ejs文件_Javascript_Express_Ejs - Fatal编程技术网

Javascript 在客户端呈现ejs文件

Javascript 在客户端呈现ejs文件,javascript,express,ejs,Javascript,Express,Ejs,目前正在尝试开发一些关于克隆“项目”模板的ajax,在每个post请求之后,我尝试将带有新项目(克隆项目)信息的ejs模板插入到ejs主页面。但我似乎找不到正确的方法,正确地执行。我跟随了文档,有前端ejs脚本 当前获取错误: resp未定义 项目显示是所有项目的ejs模板 “库存滚动列表”是包含所有项目的div resp是新创建/克隆的项(mongoose) //使用ajax克隆项目(需要显示新项目) $('.cloneItemButton')。单击(函数(){ const itemId=$(

目前正在尝试开发一些关于克隆“项目”模板的ajax,在每个post请求之后,我尝试将带有新项目(克隆项目)信息的ejs模板插入到ejs主页面。但我似乎找不到正确的方法,正确地执行。我跟随了文档,有前端ejs脚本

当前获取错误: resp未定义

项目显示是所有项目的ejs模板 “库存滚动列表”是包含所有项目的div resp是新创建/克隆的项(mongoose)

//使用ajax克隆项目(需要显示新项目)
$('.cloneItemButton')。单击(函数(){
const itemId=$(this.attr('id'))
$.ajax({
方法:“POST”,
url:“/item/”+itemId+“/clone”,
成功:功能(resp){
console.log('克隆的项目:'+响应id)
var html=ejs.render(“”)
$('.inventory scroll list').append(html)
},
})
})

我正在获取exports.fileloader不是函数…未捕获类型错误:ejs:1>>1 | exports.fileloader不是函数尝试以下操作:-我认为问题是浏览器无法访问/itemDisplay。您可以将itemDisplay.ejs的内容作为字符串存储在变量中,并使用它而不是使用include函数
// cloning item with ajax (need to display new item)
$('.cloneItemButton').click(function () {
    const itemId = $(this).attr('id')
    $.ajax({
        method: 'POST',
        url: '/item/' + itemId + "/clone",
        success: function (resp) {
            console.log('Item Cloned: ' + resp._id)
            var html = ejs.render('<%- include("/itemDisplay",  { item: resp }); %>')

            $('.inventory-scroll-list').append(html)
        },
    })
})
var html = ejs.render('<%- include("/itemDisplay",  { item: resp }); %>')
template = 'The entire contents of the ejs file';
var html = ejs.render(template,  { item: resp});