如何在我的表单中更改选定值后使用GET值调用url:
例如:我选择<option value="dog">Dog</option>
并且此网址正在运行:
www.mysite.com?query=dog
<form>
<select class="select-box">
<option name="query" value="dog">Dog</option>
<option name="query" value="cat">Cat</option>
<option name="query" value="pig">Pig</option>
</select>
</form>
答案 0 :(得分:1)
$(".select-box").on("change", function() {
var query = $('.select-box').find(":selected").text();
$.ajax( ... pass in url and
data: {query : query}
)
}
答案 1 :(得分:1)
$(document).ready(function(){
$(".select-box").change(function () {
$.ajax({
url: "www.mysite.com"
type: 'get', //a http get request
data: {
query: $(this).find("option:selected").val()
}
success: function (response) {
alert(response); //handle response here
}
});
});
});