[英]passing db url as ajax parameter
I have a controller written in python cherrypy that should check if a db url is valid by attepting to make a connection. 我有一个用python cherrypy编写的控制器,它应该通过注册建立连接来检查数据库URL是否有效。 I'm having problems however passing the parameter to the method.
我有问题,但将参数传递给方法。 My ajax call is:
我的ajax电话是:
$.ajax({ async : false,
type: 'POST',
url: "/settings/check_db_url/"+db_url ,
success: function(r) { alert(r) },
error: function(r) { alert('failure') }
});
Now the problem the urls that I need to test are in the form of: 现在问题我需要测试的网址是:
'sqlite':'sqlite:///Users/Home/tvb-database.db' or
'postgresql+psycopg2://postgres:root@127.0.0.1:5432/tvb?user=postgres&password=postgres'
For the sqlite part I managed to pass it if I do something like: 对于sqlite部分,如果我执行以下操作,我设法传递它:
db_url = db_url.split('/').join('__')
db_url = db_url.split(':').join('x_xxx_x')
And then replace back in python. 然后在python中替换回来。 But this seems so hacky to me and for the postgress part I guess I'll have to replace some more.
但这对我来说似乎太过苛刻了,对于违规部分,我想我将不得不更换一些。 So what is the correct way to handle this?
那么处理这个问题的正确方法是什么?
Send it as part of a POST parameter and not as part of the url using the data
option: 将其作为POST参数的一部分发送,而不是使用
data
选项作为url的一部分:
$.ajax({
async : false,
type: 'POST',
url: '/settings/check_db_url',
data: { db_url: db_url },
success: function(r) { alert(r) },
error: function(r) { alert('failure') }
});
And in your server read the db_url
POST parameter. 并在您的服务器中读取
db_url
POST参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.