I have a view_mine_and_others.php
file that outputs this html
<div class="rec" id="1">
<div class="val">343</div>
<a class="change">Change</a>
</div>
<div class="rec" id="2">
<div class="val">12001</div>
<a class="change">Change</a>
</div>
<div class="rec" id="3">
<div class="val">4233</div>
<a class="change">Change</a>
</div>
I have the links (<a class="change">
) bound to a js function function change()
that reads the id and val
of the record involved, with the attention to send this data off to an update.php
script.
$("a.change").click(change);
function change(){
var id = $(this).parent().attr('id');
var val = $(this).siblings('.val').html();
/* this I'm guessing is where I call the ajax code */
/* I then have some code here to udpate the interface if successful *
}
update.php
will check if the user is authorized to make this change and will make the change if so. It will also set $success = 0 or 1
depending as a success indicator. This $success
isn't returned in any way since it's not a function, it's just an internal variable that I have in the update script that could be used if needed.
- How do I make the ajax call such that I get feedback whether the update was allowed (
$success=1 in update.php
) or not (success = 0 in update.php
). I'll use that feedback to update the interface differently.
Extra info:
Note that I opted not to use a form :) just doing with the
<a>
The update.php script is expecting a
$_POST['id']
and$_POST[val]
(I'm not going to post the code for update.php here since it's not the point, I'm sure you can imagine what it looks like and what it does)