javascript - Javascript调用Python不打印任何东西
问题描述
所以我的目标是将HTML页面接收到的变量传递给python文件,然后分阶段调用python文件,使其将信息插入到SQL数据库中。仅当 javascript 的某个功能最终成功时,才应运行 python。然而,似乎即使知道 python 文件在网络部分运行,尽管在代码的不同点有打印语句,但它什么也不做。Javascript:
if (otp.length == 6 && otp != null) {
$.ajax({
url : 'controller.php',
type : 'POST',
dataType : "json",
data : input,
success : function(response) {
$("." + response.type).html(response.message)
$("." + response.type).show();
console.log(response);
$.ajax({
type: "POST",
url: "python.py",
data: { response},
dataType : "json",
}).done(function( response ) {
console.log('--response--', response)
// do something
});
},
error : function(data) {
console.log(data)
alert("Error encountered. Please try again later.");
}
});
}
Python代码
print("Felicitations. La code marche")
import MySQLdb
from flask import Flask,render_template,request
app=Flask(__name__)
@app.route('/')
def index():
return render_template('add.html')
@app.route('/',methods=['POST'])
def getvalue():
Gender=request.form['Gender']
return Gender
print(getvalue.Gender)
db=MySQLdb.connect("localhost", "name", "password", "fintech")
insertrec = db.cursor()
sqlquery= "INSERT INTO customers(Gender) VALUES('Gender')"
insertrec.execute(sqlquery)
db.commit()
print("Felicitations. La code marche")
db.close()
这是控制台/网络中显示的内容: 此信息不是由 python 打印的,而是由另一个 php 代码打印的,因此无关紧要
解决方案
推荐阅读
- biztalk - 将两条记录映射到同一个节点,其中一个是另一个子记录的迭代
- python-2.7 - 决策树分类器,多标签输出
- javascript - 了解 ES6 速记
- reactjs - React: Rxjs/Redux-Observable IE 异常被抛出但未被捕获
- html - 向 iframe 添加页眉和页脚?
- python - 在 Python 中叠加两个 Voronoi 图
- maven - Maven依赖冲突
- vba - Excel VBA 从不同的工作表复制特定列
- bash - 运行包含 postgresql 脚本的 bash 脚本失败
- html - Google PDF 查看器默认适合宽度嵌入