[英]Variable not working in simple Ajax post
Can't seem to get the variable getID to work. 似乎无法使变量getID正常工作。 I'm trying to change the html of the div.
我正在尝试更改div的html。 I know that the variable has the right value.
我知道该变量具有正确的值。
$('.cardid').change(function() {
var getID = $(this).attr('value');
$.ajax({
type: "POST",
url: "inc/change_thumbnail.php",
data: "id="+getID,
cache: false,
success: function(data) {
$("#"+getID).html(data);
alert("success");
},
error: function (err) {
alert("error");
}
});
});
将$ .ajax中的数据作为数据:{id:getID}而不是数据:“ id =” + getID,
Use val to get the value of an input : 使用val来获取输入值:
var getID = $(this).val();
As you're making a POST request, you should also use the data argument to let jQuery properly send the value : 在发出POST请求时,还应该使用data参数让jQuery正确发送值:
$.ajax({
type: "POST",
url: "inc/change_thumbnail.php",
data: {id:getID},
cache: false,
success: function(data) {
$("#"+getID).html(data);
alert("success");
},
error: function (err) {
alert("error");
}
});
You can try this: 您可以尝试以下方法:
$('[id="'+getID+'"]').html(data);
and yes you should pass it this way: 是的,您应该以这种方式通过它:
data:{id:getID}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.