gpt4 book ai didi

jquery - 在 Jquery 中发送 GET 请求

转载 作者:行者123 更新时间:2023-12-01 04:54:10 25 4
gpt4 key购买 nike

我有以下代码

$("#autocomplete").autocomplete({
source: ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"],
close: function (event, ui) {
alert($(this).val());
}
});



<label for="autocomplete">Select a programming language:</label>
<input id="autocomplete">

如何发送作为 GET 函数获得的值?我阅读了 Ajax GET 函数,但不确定如何对从表单元素获取的数据进行编码

最佳答案

您可以使用序列化

它将一组表单元素编码为字符串以供提交。

http://api.jquery.com/serialize/

这就是你如何做到的

<form id="myform">
<label for="autocomplete">Select a programming language:</label>
<input id="autocomplete" name="autocomplete">
<input type="button" id="btnSubmit" value="send">
</form>

<script>
$(document).ready(function(){

$("btnSubmit").click(function(){
$.ajax({'url':'myurlforajaxrequest',
'data': $("#myform").serialize(),
'type':'get'
});
});

});
</script>

关于jquery - 在 Jquery 中发送 GET 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15963603/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com