Search code examples
phpajaxhref

How to make a php a href post value use ajax?


I want to post a value using a href with target_self, but I do not want to refresh the page when it posts. How to add a ajax function?

<form name="info" id="info" method="post" action="index.php" >
<input name="name" type="hidden" value="test" /><br />
<a href="javascript:document.name.submit()">test</a>
<form>

Solution

  • With ajax the page is never refreshed, you will just POST data to your webserver, if you want to stop page refresh after ajax just add this at the end of ajax function

    return false;
    

    assuming you use JQuery:

       $("form").submit(function(){
    
          $.ajax(); // Which needs some other stuff for making it useful
    return false; //This will stop the page from refresh !
    });
    

    And please show some code so we can batter understand what you want.