呈上题
我正在使 javascript ajax 调用 python 结果,但新数据未从 .py 脚本返回
环境:windows、python,我在visual studio code中用live server打开
<!DOCTYPE html>
<html>
<body>
<p id="demo">original data</p>
<script type="text/javascript">
$.ajax({
type: 'POST',
url: 'get_sql_where_02.py',
data: {data_sent:'Send this to python script'},
success: function(data) {
document.getElementById("demo").innerHTML = data;
}
});
</script>
</body>
</html>
- get_sql_where_02.py
```
import mysql.connector
import webbrowser
import time
import pymysql
import sys
import ast
mydb = mysql.connector.connect(
host="196.8.98.141",
user="root",
password="password",
database="data_db",
auth_plugin='mysql_native_password'
)
mycursor = mydb.cursor()
mycursor.execute("SELECT P_TITLE,P_PRODUCT FROM webpage WHERE P_ID = '001'")
myresult = mycursor.fetchall()
print(myresult)
data_to_pass_back = myresult
```