使用Ajax调用在Exist-DB中创建数据库条目 [英] Creating database entries in Exist-DB with Ajax calls

查看:66
本文介绍了使用Ajax调用在Exist-DB中创建数据库条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开发一个独立的exist-db应用程序时,我在ajax调用期间传递用户身份时遇到了一些问题.

While developing a self-contained exist-db app I ran into some issues with passing on the user's identity during an ajax call.

我创建了一个标准页面,该页面允许用户使用他或她的标准exist-db帐户登录.(或多或少基于此 https://github.com/eXist-db/existdb-登录).

I have created a standard page that allows the user to login in with his or her standard exist-db account. (It's more or less based on this https://github.com/eXist-db/existdb-login ).

在某些时候,用户需要创建自己的条目并上传文件,这是通过ajax脚本完成的(我使用的是Kartik的bootstrap uploader,但它基本上是标准的ajax上传功能):

At some point, the users need to create their own entries and upload files, and this is done with an ajax script (I'm using Kartik's bootstrap uploader, but it's basically a standard ajax upload function):

$('#input-24').fileinput({

        uploadUrl: "../modules/uploader.xql",
        uploadAsync: true,

        fileActionSettings : {
            uploadExtraData() {

                return {
                    'FileName': $(this).data('title'),

                }
            }
        },
    });  

现在,这当然会失败,因为它看起来像GUEST用户正在尝试创建条目,此操作仅适用于注册用户.

Now, of course, this will fail, since it will appear like a GUEST user is trying to create entries, which is an action that is allowed only for registered users.

existent-db是否允许在这种情况下发送我的登录凭据,而不必诉诸标准的HTTP登录(这是有问题的,因为这意味着创建一个cookie来存储密码,这或多或少会呈现该密码).整个登录诉讼都存在无用的机制),还是有什么方法可以使用控制器代替外部脚本?

Does exist-db allow a way to send in my login credentials at this point without having to resort to the standard HTTP login (which is problematic, since it means creating a cookie to memorize the password, which more or less renders the whole login suing exist's mechanisms useless), or is there any way to use the controller instead of an external script?

提前谢谢!

推荐答案

要使eXistdb会话与XHR(Ajax请求)一起使用,您需要确保

To have an eXistdb session work with XHR (Ajax requests) you need make sure that

login:set-user('my.login.domain',(),false())

在控制器中调用之前,将其转发到请求处理程序.否则,所有请求似乎都来自来宾"用户.

is called in the controller before you forward it to your request handler. Otherwise all request will seem to originate from the 'guest' user.

如果您要使用原始/原生JavaScript请求,例如提取,您还需要告诉它向请求中添加凭据:

If you want to use vanilla/native JavaScript requests e.g. fetch you also need to tell it to add the credentials to the request:

fetch(URL,{凭证:"same-origin",方法:"GET"})

顺便说一句,在exidtb-login中使用的永久登录可能使用cookie值来获取存储在服务器上的会话变量(JSESSIONID),但我需要检查一下.

By the way, the persistent login used in exidtb-login likely uses a cookie value to pick up the session variables stored on the server (JSESSIONID), but I need to check that.

这篇关于使用Ajax调用在Exist-DB中创建数据库条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆