javascript - Sending data using Ajax data not sending to PHP -


i'm trying use ajax send form data, on php page it's not echoing. i'm new ajax not sure if have done wrong it.

here's have:

$(function () {      $('form').on('submit', function (e) {        e.preventdefault();        $.ajax({         type: 'post',         url: 'two.php',         data: $('form').serialize(),         success: function () {           alert('form submitted');         }       });      });    }); 

one of form fields has name="selection" , id="selection" in two.php i'm trying simply:

echo $_post['selection']; 

but nothing set.
ideas?

you should passing response (from two.php) success callback:

    success: function ( response ) {       alert( 'submitted data: ' + response );     } 

which should work provided selection set. (check in console under network requests confirm this)

also, consider adding error callback:

  error: function( response, errorthrown ){       alert( 'request failed: ' + errorthrown );   } 

to report ajax errors.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -