2

I want to submit a form without refresh page. My case is different than most people, I only need to initial the form submit, and then in the php, if $_POST, then gather the value. It is not duplicate question, because most answers are sending the form value to .ajax url and send the value back to html. I just want to initialize the submit.

$.ajax({
    url:'member_search.php',
    type:'POST',
 data:{
      search_text: $(".result_tag").text()
 }
    
  });
<form action="" method="post" name="form">
  <input type="hidden" id="word" value="hello" name="input" >
  </form>

<?php
if ($_POST){
  $value=$_POST['input'];
   echo $value;



?>
conan
  • 1,327
  • 1
  • 12
  • 27

1 Answers1

0

Post always refreshes the page with form handling. I suggest using a webservice or controller to handle the request. The you can call it via ajax.

Casey ScriptFu Pharr
  • 1,672
  • 1
  • 16
  • 36
  • what is webservice or controller? Is some kind of tool? I am using wordpress, I don't know if it's available or not. – conan Mar 01 '15 at 00:54
  • You can also just post using ajax post, and that will not refresh teh page. You are currently using a from to do so, and that always will. A web service is a url you hit, and it returns a result for you. For example of a web service you can read the following: http://stackoverflow.com/questions/6323338/jquery-ajax-posting-json-to-webservice – Casey ScriptFu Pharr Mar 01 '15 at 20:57
  • Thanks for your time. What do you mean by using ajax post? Look at my code above, I think I am using the ajax post already, correct me if I was wrong. My code will run when I load the page, but just doesn't work with if($_POST){} – conan Mar 01 '15 at 21:35