获得即时的ajax响应

I think there is a way to do this in ajax. But if you have a better way please let me know.

I have this code:

      $interactionBox= '<input type="button" value="Pending Friend Requests('.$num_rows.')" onclick="return false" onmousedown="javascript:toggleInteractContainers(\'friend_requests\');"/>';  

This code opens up a togle box where user can accept friends if there is a pending request. So if button looks like this:

    Pending Friend Request(1)

And user accepts that request user has to refresh the page for this to show as:

    Pending Friend Request(0)

Is there a way to do this without refreshing the page using ajax or any other way?

Here is HTML for above code:

<div class="interactContainers" id="add_friend">
            <div align="right"><a href="#" onclick="return false" onmousedown="javascript:toggleInteractContainers('add_friend');">cancel</a> </div>
             Add <?php echo $username; ?> as a friend? &nbsp;
             <a href="#" onclick="return false" onmousedown="javascript:addAsFriend(<?php echo $req_user_id; ?>, <?php echo $username_id; ?>);">Yes</a>

You can just get the value between brackets with JavaScript and then reduce by 1, You can get that value (if it isn't a variable get via regexpresion:

var button = document.getElementById('buttonid'); // fill in the id
button.value = "Pending Friend Requests("+ (parseInt(button.value.match(/\d{1,10}/)) - 1) + ')';

just excute that after each accept (or not-accept)

note you should just use the function in onclick, it's not a link so it will only excute the javacript bit: so no onmousedown just onclick="javascript:toggleInteractContainers(\'friend_requests\');"

look ma: no jQuery!