我做了一个选择框:
<select name="template" id="template" class="select">
<option value="template">Template_NL</option>
<option value="template_fr">Template_FR</option>
</select>
如果用户更改了选择框,我想根据服务器端的该值更改 url。我可以通过 ajax 请求来做到这一点吗?
<script>$(function() {
$("#template").change(function() {
var Template = document.getElementById("template").value;
$.ajax({
url: "mailing-edit2.asp",
data: Template,
success: function(){
data = response;
location.reload();
}});
});
</script>
最佳答案
您应该将响应添加到回调调用作为参数:
$("#template").change(function() {
var Template = document.getElementById("template").value;
$.ajax({
url: "mailing-edit2.asp",
data: {'template': Template},
success: function(response){
//If you return the new url
location.href = response;
}
});
});
注意:location.href
会将您重定向到给定的网址。
希望这有帮助。
关于javascript - HTML Selectbox 值 ajax 调用用于页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42441699/