【发布时间】:2015-04-29 01:16:15
【问题描述】:
我有 2 个 python 文件:gui.py & index.py
python.py 包含来自 mysql 数据库的记录的表。
gui.py 包含 python.py 和带有发送消息按钮的文本字段。
另外,gui.py 包含将加载带有参数的新 python.py 的 javascript。
gui.py 脚本
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#content").load("http://localhost/index.py");
$("button").click(function(){
var url = "http://localhost/index.py?name=1&message=";
var msg = document.getElementById("message").value;
var res = url.concat(msg);
alert(res); //here I always can understand that result URL is okay.
$("#content").load(res);
});
</script>
和index.py部分
cursor.execute("INSERT INTO `messages` (`sender`, `receiver`, `text`, `time`) VALUES ('" + req.form['name'] + "', '3', '" + req.form['message'] + "', now())")
});
req 来自def index(req): 我正在使用 mod_python。
所以,问题是 - 当我尝试发送带有空格的消息时 - 我的表格消失了(直到下一页刷新(但我不需要在没有空格的情况下刷新它,ajax 加载在这里效果很好))。然后我将只看到消息的第一个字。正如您在我的代码中看到的那样,如果我复制该警报并运行该 url,我有 alert(res); - 空格很好用。
一些细节
我正在使用 ubuntu 14.04、apache2、mod_python、python 2.7、mysql 数据库、python-MySQLdb。
【问题讨论】:
标签: javascript python ajax mod-python