I want to create a simple javascript button that will be disabled once the current user clicked it.
I have a zend framework action that I d like to be called开发者_开发知识库 once the user clicks it but disabled the button for ever, if the current user already clicked it.
My zend framework action is something like this: `public function addvisitedlocationAction() {
$locationID = $this->_getParam('location_id');
echo "Location ID: " . $locationID;
$visited = 1;
$memberID = $this->view->identity;
$email= $memberID->email;
$currentUser = Model_DbTable_Members::getMember($email);
$memberID2 = $currentUser['id'];
echo '<br>Current Member id: ' . $memberID2;
//$profile = Model_DbTable_Members::findMembersProfile($email);
$this->view->currentMember = $currentUser;
//$this->view->theProfile = $profile;
$visitedModel = new Model_DbTable_MembersVisitedLocations();
$visitedModel->addMemberVisitedLocation($memberID2, $locationID,$visited);
return $this->_redirect('/restaurant/viewrestaurantlocationprofile/location_id/'. $locationID);
}//end of addvisitedLocation;`
I want to call this once the javascript button is clicked and disable the button for ever for that user.
My problem is I am familiar with javascript but don't really know where to start from. I have a simple image that I can use as a button. My aim is to call that action without redirecting the page and disable the button for the current user.
Any suggestions how I can achieve that?
Thanks.
If you want to call another page without reloading or redirecting the user then you'd need to use AJAX.
Using jQuery, you can do it like this:
function whatever()
{
$.ajax({
type: "GET",
url: "/my/action/to/call",
data: "mydataitem="+dataitem,
success: function(html, msg){
//do something on success
}
});
}
This will allow you to send data to another Zend Action, which can then process your request.
To disable the button, you can just do $('#myidofbuttonOrimage').attr('disabled', 'disabled');
If you're using a library such as jQuery, this is very simple, otherwise here's some links that may help you.
Hope this helps
Reference: http://api.jquery.com/jQuery.ajax/ Reference: http://www.w3schools.com/ajax/default.asp
精彩评论