Submit form without page reloading

后端 未结 17 2455
无人及你
无人及你 2020-11-22 00:45

I have a classifieds website, and on the page where ads are showed, I am creating a \"Send a tip to a friend\" form...

So anybody who wants can send a tip of the ad

17条回答
  •  伪装坚强ぢ
    2020-11-22 01:23

    function Foo(){  
       event.preventDefault(); 
     $.ajax(   {  
          url:"Controllername/ctlr_function",
          type:"POST",
          data:'email='+$("#email").val(),
          success:function(msg)      {  
             alert('You are subscribed');
          }
       }   );
    }
    

    I tried many times for a good solution and answer by @taufique helped me to arrive at this answer.

    NB : Don't forget to put event.preventDefault(); at the beginning of the body of the function .

提交回复
热议问题