[英]Pass Form Element Value to Ajax Post Method on an onChange Event
so I have a this form select which I want to pass the value in ajax using the onChange event. 所以我有一个这样的表单选择,我想使用onChange事件在ajax中传递值。
<select name="someName" id="someName" onChange="changeSomething()">
<option value="1">Value 1</option>
<option value="2">Value 2</option>
<option value="3">Value 3</option>
<option value="4">Value 4</option>
</select>
<div id="base_url"></div>
<script>
function changeSomething() {
$.ajax({
url: "http://example.com/ajax/command/change_something.php",
type: "POST",
async: true,
cache: false,
data: {
"key": "2qsKeJrQNLE1GoFrnWpL",
"base_url": "http://example.com/",
"id": $("#someName").val() // I want to get the value of this one
},
success: function (data) {
$("#base_url").html(data);
}
});
}
</script>
Is there another way to pass the value of any form element especially on an onChange Event? 还有另一种方法来传递任何表单元素的值,尤其是在onChange事件上吗? Am I doing it wrong?
我做错了吗? Please help!!
请帮忙!! T_T
T_T
You can serialize your form elements with the $.serializeArray() JQuery function 您可以使用$ .serializeArray()JQuery函数序列化表单元素
See the doc at http://api.jquery.com/serializeArray/ 请参阅http://api.jquery.com/serializeArray/中的文档
check this one: 检查这一:
<select name="someName" id="someName" onChange="changeSomething(this.value)">
function changeSomething(id)
"id": id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.