user3103915 user3103915 - 1 year ago 94
Ajax Question

Submit a link using javascript or jquery without refreshing a page

I have a link which invokes an API which saves a session. Suppose my API be present on and my link is as below :

<a href="" >Click here </a>

Now i don't want to refresh the page. Just use JQuery or Javascript to simply execute the link and give an alert like "Action Succesfull". I don't see the point of using AJAX as I don't require any database actions from my side. Thanks

Answer Source

The point of AJAX is not to do database actions, its to comunicate with the server without needing to reload the page. I think your description qualifies for the use of AJAX, since you do expect a answer from the server, and you do not want to reload the page.

You could also open a iframe, or a new window, but ajax might be the solution here.

Keep in mind you need to cancel that event when you click on the anchor.

So, with ajax you could so something like:

$('a').on('click', function(e) {
  var href = this.getAttribute('href');
    url: href,
    success: function(text) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download