javascript - 在提交之前在表单中调用 ajax,显示“未捕获的 ReferenceError”
问题描述
我正在尝试从表单内部调用 ajax 函数来提取下拉列表的值。
mypython.py
@app.route('/new_data', methods = ['POST', 'GET'])
def new_data():
#Filter data and return the data(data_list,filter_function_url) to myhtml.html file
myhtml.html
<div>
<form ....method="POST" action="{{url_for('submit_new_data')}}" method="POST" enctype="multipart/form-data">
....
....
<select id="selected_data" onchange='get_subdata_filters("{{ filter_function_url }}")'>
<option disabled selected>Please Select Partner State</option>
{% for f in data_list %}
<option value="{{f}}">{{f}}</option>
{% endfor %}
</select>
</form>
</div>
myjsfile.js
这确实可以正常工作,来自 id 和 get from 的值确实在selected_data
控制台上正确显示,没有任何错误html file
selected_option_data_filter_url
html
filter_function_url
function get_subdata_filters(selected_option_data_filter_url) {
var selected_data = document.getElementById("selected_data").value;
// make the user selected data into a dictionary/json
var new_selected_data = {
s_data:selected_data
};
console.log(new_selected_data);
console.log(selected_option_data_filter_url);
}
ajax
当我在我的 js 函数中添加一个调用时select
function get_subdata_filters(selected_option_data_filter_url) {
var selected_data = document.getElementById("selected_data").value;
// make the user selected data into a dictionary/json
var new_selected_data = {
s_data:selected_data
};
console.log(new_selected_data);
console.log(selected_option_data_filter_url);
$.ajax({
type: "POST",
contentType: "application/json;charset=utf-8",
url: selected_option_data_filter_url,
traditional: "true",
async:false,
timeout: 40000,
data: JSON.stringify({new_selected_data}),
dataType: "json",
success: function(fselected_data){
console.log(fselected_data)
};
});
}
Uncaught ReferenceError: get_subdata_filters is not defined
我在检查时收到此错误
console
做错了什么?我该如何纠正?
解决方案
ajax
您的通话中有错误。在成功之后
删除并在您的之后添加;
;
console.log()
function get_subdata_filters(selected_option_data_filter_url) {
var selected_data = document.getElementById("selected_data").value;
// make the user selected data into a dictionary/json
var new_selected_data = {
s_data:selected_data
};
console.log(new_selected_data);
console.log(selected_option_data_filter_url);
$.ajax({
type: "POST",
contentType: "application/json;charset=utf-8",
url: selected_option_data_filter_url,
traditional: "true",
async:false,
timeout: 40000,
data: JSON.stringify({new_selected_data}),
dataType: "json",
success: function(fselected_data){
console.log(fselected_data);
}
});
}
推荐阅读
- c++ - 将无限参数传递给 C++17 中的日志记录函数
- docker - “docker run --rm hello”运行到“失败:没有这样的文件或目录”错误
- gnuplot - gnuplot 等高线图阴影线
- python - 透视时将两组不同的列视为单个索引和列
- latex - 如何使用 esttab 在 LaTeX 输出的变量标签中包含“&”?
- ios - 试图在 ios (native api) 上实现对 TabView 的幻灯片动画
- vb.net - 代码崩溃 Visual Studio - 有什么方法可以重写吗?
- php - 代客不工作。项目不在路径中运行
- javascript - 我需要知道如何仅使用 Javascript 创建下拉菜单,不涉及其他编程语言
- sql - Oracle -- 在预期的地方找不到 FROM 关键字