好的家伙希望你也可以帮我这个。我不会疯狂地了解jQuery和AJAX,可能我错过了很简单的东西。我无法传递超过1个变量。我已经尝试了几种不同的东西,最接近我的工作this,但即使这样也没有用。
的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 }
,它就不会显示加载在警告框中的数据(如果我尝试显示两个变量的信息,那么它只会将一个变量提交给< strong> 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');
}
}
希望你能告诉我在哪里犯了错误以及如何纠正错误。 谢谢你提前!
答案 0 :(得分:4)
使用JS / JQUERY POST AJAX REQUEST。以下是我用于所有AJAX调用的语法。
var first = 'something';
var second = 'second';
var third = $("#some_input_on_your_page").val();
///////// AJAX //////// AJAX //////////
$.ajax({
type: 'POST',
url: 'page_that_receives_post_variables.php',
data: {first:first, second:second, third:third},
success: function( response ){
alert('yay ajax is done.');
$('#edit_box').html(response);//this is where you populate your response
}//close succss params
});//close ajax
///////// AJAX //////// AJAX //////////
PHP页面的代码page_that_receives_post_variables.php
<?php
$first = $_POST['first'];
$second = $_POST['second'];
$third = $_POST['third'];
echo 'now do something with the posted items.';
echo $first; //etc...
?>