Jquery/PHP更新后显示数据库
我有一个jQuery,它在blur上更新DB。它工作正常,除了我希望代码在更新后显示当前的DB值。数据库中有一个值,该字段中的金额将被添加到该值中并得到更新。现在唯一能看到这一点的方法是在每次更新某些内容时刷新页面Jquery/PHP更新后显示数据库,php,jquery,Php,Jquery,我有一个jQuery,它在blur上更新DB。它工作正常,除了我希望代码在更新后显示当前的DB值。数据库中有一个值,该字段中的金额将被添加到该值中并得到更新。现在唯一能看到这一点的方法是在每次更新某些内容时刷新页面 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script> <scr
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript">
// JQUERY: Plugin "autoSumbit"
(function($) {
$.fn.autoSubmit = function(options) {
return $.each(this, function() {
// VARIABLES: Input-specific
var input = $(this);
var column = input.attr('name');
// VARIABLES: Form-specific
var form = input.parents('form');
var method = form.attr('method');
var action = form.attr('action');
// VARIABLES: Where to update in database
var where_val = form.find('#where').val();
var where_col = form.find('#where').attr('name');
// ONBLUR: Dynamic value send through Ajax
input.bind('blur', function(event) {
// Get latest value
var value = input.val();
// AJAX: Send values
$.ajax({
url: action,
type: method,
data: {
val: value,
col: column,
w_col: where_col,
w_val: where_val
},
cache: false,
timeout: 10000,
success: function(data) {
// Alert if update failed
if (data) {
document.getElementById("notice").innerHTML="Error, NO UPDATE";
}
// Load output into a P
else {
$('#notice').text('Updated');
$('#notice').fadeOut().fadeIn();
}
}
});
// Prevent normal submission of form
return false;
})
});
}
})(jQuery);
// JQUERY: Run .autoSubmit() on all INPUT fields within form
$(function(){
$('#ajax-form INPUT').autoSubmit();
});
</script>
HTML内容
PHP文件将行插入数据库后,让它从数据库中选择新值,并在对jQuery的AJAX响应中回显该值。然后使用jQuery将新值填充到您希望它去的任何地方。我键入了几乎完全相同的内容:
<label>Total:</label>
<input name="company" value="<?php echo $row['total'] ?>" />
<label>Tax-in:</label>
<input name="lastname" value="<?php echo $row['taxin'] ?>" />