user3026745
user3026745

Reputation: 15

Submit a link without refreshing and without ajax

I have a link that when you click it gets an image and saves it to the server

I want to make it so when you click a link in a list, it runs the script but it doesn't actually go to the page. I tried e.preventdefualt but then that doesn't submit the link

<li><a href="view.php?id=867hjhgjghj">867599386384729100r</a></li>

That would run the php necessary to save the image on the server, I know how I'd do this with ajax but I saw a site doing it without.

$('#lia').click(function (e) {
  e.preventDefault()
});

Upvotes: 0

Views: 126

Answers (1)

Bill Criswell
Bill Criswell

Reputation: 32921

You could accomplish this with AJAX by doing:

$('a').on('click', function(e){
  e.preventDefault();
  $.get(this.href);
});

I know the title says without refreshing or ajax, but I think that was a mistake.

Upvotes: 3

Related Questions