Javascript 使用ajax和php基于文本框更改的更改查询
我一直在尝试使用php和ajax更改查询。事情是这样的Javascript 使用ajax和php基于文本框更改的更改查询,javascript,php,jquery,mysql,ajax,Javascript,Php,Jquery,Mysql,Ajax,我一直在尝试使用php和ajax更改查询。事情是这样的 我有一个下拉列表,当它被更改时,它会将所选数据复制到一个文本框中,这是我使用javascript实现的 $(document).ready(function () { $("#animaloption").change(function () { $('#animalfilter').val($("#animaloption").val()); }); }); 然后 我需要检查id为animalfilt
$(document).ready(function () {
$("#animaloption").change(function () {
$('#animalfilter').val($("#animaloption").val());
});
});
$(document).ready(function () {
$("#animaloption").change(function () {
$('#animalfilter').val($("#animaloption").val());
var animal= $('#animalfilter').val($("#animaloption").val());
$.ajax({
url: "ajax/test.php",
type: "post",
data: animal,
success: function (response) {
$("#kind").html(response);
}
});
});
});
<?php
$a = "SUCCESS";
return $a;
?>
请帮帮我
谢谢。您这里有几个问题,我将注意关注的领域: jQuery:
$(document).ready(function() {
// Not necessary, but better to use .on() here
$("#animaloption").on('change',function() {
// Use $(this) instead, grabs the selected value. No sense in
// capturing the same event value when you have it in this event already
var animal = $(this).val();
// Assign value here to field
$('#animalfilter').val(animal);
// Start ajax
$.ajax({
// Make sure this is the correct path
url: "ajax/test.php",
type: "post",
data: animal,
success: function(response) {
$("#kind").html(response);
}
});
});
});
/ajax/test.php
<?php
$a = "SUCCESS";
# You have to echo, not return
echo $a;
# Try print_r() for sure-fire results testing
print_r($_POST);
您在这里遇到了一些问题,我将关注以下方面:
jQuery:
$(document).ready(function() {
// Not necessary, but better to use .on() here
$("#animaloption").on('change',function() {
// Use $(this) instead, grabs the selected value. No sense in
// capturing the same event value when you have it in this event already
var animal = $(this).val();
// Assign value here to field
$('#animalfilter').val(animal);
// Start ajax
$.ajax({
// Make sure this is the correct path
url: "ajax/test.php",
type: "post",
data: animal,
success: function(response) {
$("#kind").html(response);
}
});
});
});
/ajax/test.php
<?php
$a = "SUCCESS";
# You have to echo, not return
echo $a;
# Try print_r() for sure-fire results testing
print_r($_POST);
我需要检查id为animalfilter的输入文本框是否已更改,然后使用ajax进行查询
两个人
$(document).ready(function () {
$("#animalfilter").change(function () {
$('#animalfilter').val($("#animaloption").val());
// var animal= $('#animalfilter').val($("#animaloption").val()); //<-- i highly doubt you need this
var animal= $('#animalfilter').val(); //<-- rather this
$.ajax({
url: "ajax/test.php",
type: "post",
data: animal,
success: function (response) {
$("#kind").html(response);
}
});
});
});
$(文档).ready(函数(){
$(“#动物过滤器”)。更改(函数(){
$('animalfilter').val($('animaloption').val());
//var animal=$('#animalfilter').val($(“#animaloption”).val()//
我需要检查id为animalfilter的输入文本框是否已更改,然后使用ajax进行查询
两个人
$(document).ready(function () {
$("#animalfilter").change(function () {
$('#animalfilter').val($("#animaloption").val());
// var animal= $('#animalfilter').val($("#animaloption").val()); //<-- i highly doubt you need this
var animal= $('#animalfilter').val(); //<-- rather this
$.ajax({
url: "ajax/test.php",
type: "post",
data: animal,
success: function (response) {
$("#kind").html(response);
}
});
});
});
$(文档).ready(函数(){
$(“#动物过滤器”)。更改(函数(){
$('animalfilter').val($('animaloption').val());
//var animal=$('#animalfilter').val($(“#animaloption”).val());//首先,您需要使用方法:“POST”
而不是类型:“POST”
。添加fail
回调可能会指示一些错误。我总是参考此文档-小写post
很好,我想你会发现它不需要post
就可以工作。让我们看看你的表单。首先,你需要使用方法:“post”
而不是键入:“post”
。添加fail
回调可能表明有一些错误。我总是参考此文档-小写post
很好,我想您会发现它不需要post
就可以工作。让我们看看您的表单。