Reputation: 87
Is it possible to call one of my JSP methods from a Javascript Onclick event?
I don't want my user to leave the current page. I need the javascript to call the method, which then runs the SQL update to increment in the database. I read somewhere I could use a hidden Iframe to accomplish this as well...
Upvotes: 0
Views: 1305
Reputation: 143
Yes you can use hidden iFrame to do this but in my opinion would be to use AJAX. If you'r using jQuery it is pretty straight forward. Just invoke an ajax request on click.
No idea how to do AJAX using jQuery? I am also pasting the links. Pretty straight forward.
http://api.jquery.com/jQuery.post/
http://api.jquery.com/jQuery.get/
http://api.jquery.com/jQuery.ajax/
Upvotes: 1
Reputation: 78006
$('myElement').click(function(){
$.ajax({
url: '/path/to/php/file.php?method=foo',
success: function(data){
// do something with data, which is the output of your php file
}
});
});
Upvotes: 1