javascript - Form ajax php not work with data serialize with action empty -


this form operated process.php in action form , work well.

but when want work in same page action empty, ajax not work (php no receiving data ajax form)

when change. data:

form.serialize(),
data: request,
form work, php receiving data ajax have problem, form refresh page.

ajax source

<script> //if form valid         else {             loading.show();             $.ajax({                 url: form.attr('action'),                 type: form.attr('method'),                 data: form.serialize(),                 success: function(){                     shownotice('success');                     form.get(0).reset();                     loading.hide();                 }             });         }          return false; //this stops submission off form , stops browsers showing default error messages      }); </script> 

html form

 <form method="post" action="" class="mailform">                       <button name="submit" type="submit" class="zbtn">sumbit message</button>              </form> 

code php

<?php if (isset($_post['submit']))  {      //here syntax form       //if not ajax request     if(empty($_server['http_x_requested_with']) && strtolower($_server['http_x_requested_with']) !== 'xmlhttprequest'){         //set session variables         session_start();         $_session['cf_returndata'] = $returndata;       } } ?> 

¿as can run form via ajax without refreshing page?

note: orinal form (demo) work process.php in action: http://goo.gl/cscbqn


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -