Ajax, send data without refreshing the page

0

Well, I did a Restful API integration, which searches all the products of an e-commerce and sends Json to another site, and needed to click the "Submit" button, the page would not update. >

My problem is as follows, there is no data to insert into form, basically I use the form just to put the submit button

        <div style="position:absolute; margin-left: 65%;margin-top: -500px">
<form action="" method="post" id="formenv">
<button style="width:60px" type="submit"     class="btn btn-primary" id="expevt" name="expevt">
     <dt style="text-align:center">
        <span class="glyphicon glyphicon-export"></span>
        <b></b>
        </button>

I can only use ajax to send the data of a form, but this button only calls the Integration Post,

    if(isset($_POST))
{
    if (isset($_POST['expevt']))
    {
        $post2 = new Posts();

        if(isset( $_POST['catwooid']) && $_POST['catwooid'] != '')
        {
            $post2->postOneCat($_POST['catwooid']);
        }else
        {
            $post2->postAllCat();
        }
        $post = new Posts();
        if(isset( $_POST['prodwoosku']) && $_POST['prodwoosku'] != '')
        {
            $post->postOneProd($_POST['prodwoosku']);
        }else
        {
            $post->postAllProd();
        }
    }
}

Would you like to do the post without giving refresh?

    
asked by anonymous 17.08.2018 / 18:36

1 answer

-1

You can put return false in your form and the rest is normal

$('#expevt').on('click', function(){
   alert('Aqui você vai fazer seu ajax enviar' )
   //$.ajax()
})
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>

<script
  src="https://code.jquery.com/jquery-3.3.1.min.js"integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
  crossorigin="anonymous"></script>
  
  
<div >
        <form action="" method="post" id="formenv">
             <button style="width:60px" type="submit"    class="btn btn-primary" id="expevt" name="expevt">
                  <dt style="text-align:center">
                  Botão
                  <b></b>
                  </dt>
              </button>
        </form>
    </div>
    
17.08.2018 / 21:02