jQuery 使用ajax获取select元素的值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16661231/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 17:33:24 来源:igfitidea点击:
Get value of a select element with ajax
提问by Igor Martins
I'm trying to get a value of a select element, but is returning Array()
我正在尝试获取 select 元素的值,但正在返回 Array()
This is my html:
这是我的 html:
<select name="data[Attorney][empresa]" id="AttorneyEmpresa">
<option value="">Selecione</option>
<option value="3">Sotreq</option>
</select>
And my Jquery:
还有我的 Jquery:
$(document).ready(function() {
$("#AttorneyEmpresa").change(function(){
$.ajax({
type: 'POST',
data: $('#AttorneyEmpresa').val()
});
});
});
What's wrong?
怎么了?
回答by Amit
回答by Jason
The data attribute should be Object type like this:
数据属性应该是这样的对象类型:
$(document).ready(function() {
$("#AttorneyEmpresa").change(function(){
$.ajax({
type: 'POST',
data: { "select" : $('#AttorneyEmpresa').val()}
})
})
});
回答by origin1tech
You need to send the day as an object.
您需要将日期作为对象发送。
var data = { somekey: $('#AttorneyEmpresa').val() }