On my website I have an update form that when submitted alters my database.
What I want to do however is have all the elements that contain the old values,
AJAX
// UPDATE
$(".bill-upd-submit").click(function() {
var elem = $(this);
$.post("update_bill.php", elem.parent(".bill-upd").serialize(), function(data) {
//INSERT INTO OLD VALUES
});
});
PHP
In my PHP I’ve tried the following with no luck, has anybody done this before or can give me advice on where I may be going wrong?
echo "elem.closest('li').find('.cost').html('');";
You do not need to have the server provide the jQuery code. You can just type it into the callback function, where you have your
//INSERT INTO OLD VALUES-comment.In the above code, the “data”-variable contains that which was given back by the server. So for that solution, make sure that
"update_bill.php"will return the HTML that you want to insert into'li .cost'.