好吧,大家希望你也可以帮助我。我不会疯狂地熟悉jQuery和AJAX,可能我错过了一些非常简单的东西。我无法传递超过1个变量。我尝试了几种不同的东西,其中最接近我的工作是this,但即使这样也行不通。如何通过jQuery将多个变量传递给PHP
jQuery的
$("#bodymes ul li span[contenteditable=true]").blur(function(){
var weight_id = $(this).attr("id") ;
var weightbody_mes = $(this).text() ;
$.post("../includes/bodymes_weight.php", { weightbodymes: weightbody_mes })
.done(function(data) {
$(".weightsuccess").slideDown(200);
$(".weightsuccess").html("Weight Updated successfully");
if ($('.weightsuccess').length > 0) {
window.setTimeout(function(){
$('.weightsuccess').slideUp(200);
}, 4000);
}
// alert("Data Loaded: " + data);
});
});
所以基本上如果我运行这个它会完全正常工作和我的PHP脚本将会处理它。请注意,当我启动并启用警报并显示加载的数据时,它会显示正确的信息(来自weightbodymes
的信息),我可以更新数据库。但只要我再添变数{ weightbodymes: weightbody_mes, weightid: weight_id }
它不会显示数据警告框加载(如果我试图表现出从它的工作这两个变量的信息,但它也只是一个变种提交给PHP是:
$weightid = $_POST['weightid'];
$weight = $_POST['weightbodymes'];
if ($insert_stmt = $mysqli->prepare("UPDATE body SET body_weight=? WHERE body_id='$weightid'")) {
$insert_stmt->bind_param('s', $weight);
// Execute the prepared query.
if (! $insert_stmt->execute()) {
header('Location: ../index.php?error=Registration failure: INSERT nwprogram1');
}
}
希望你能告诉我在哪里,我犯了一个错误,以及如何纠正它。 预先感谢您!
futher性质的'data'对象添加:'{weightbodymes:weightbody_mes,weightid:weight_id,FOO: '棒'}' – 2015-02-11 15:39:14
送东西就像这个'{'data':{'var_1':'value1','var_2':'value2'}}'然后通过$ _POST ['data'] ['var_1'],$ _POST ['数据'] ['var_2']' – NestedWeb 2015-02-11 15:39:57
这应该有你想要的东西http://stackoverflow.com/questions/8191124/send-javascript-variable-to-php-variable – MrPickles 2015-02-11 15:40:00