Create a POST with Jquery without form

Asked

Viewed 135 times

1

You can create a Submit POST without FORM?

I have some link:

<a href="1" class"submit">Teste 1</a>

<a href="2" class"submit">Teste 2</a>

<a href="3" class"submit">Teste 3</a>

When the person clicks on the link, a POST with the name href.

With the value of POST I’ll capture in php and save in bd.

1 answer

2


Look, this is simple...

Your HTML:

<a href="1" class"submit1">Teste 1</a>

<a href="2" class"submit2">Teste 2</a>

<a href="3" class"submit3">Teste 3</a>

JS

$(".submit1").click(function(){
  var a = $(".submit1").val();
  $.ajax = ({
     url: "url do que vai ser executado",
     type: "POST ou GET",
     data: {a: 'submit1'},
     dataType: "JSON",
     success: function(data){},
     error: function(data){
            console.log(data);
      }
  }),
});

And so successively for the other two... If not this, explain me better so I can understand your doubt.

  • 1

    In case the "url of the one to be executed" is the value of the href of the clicked element, i.e., $(this).prop("href")

Browser other questions tagged

You are not signed in. Login or sign up in order to post.