Craig Hopson Posted November 17, 2012 Report Share Posted November 17, 2012 hi can some one explain to me what is going on with this code please index.php <!DOCTYPE html><script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script><script>var data = 'something-here';$.ajax({ type: 'POST', url: 'post.php', data: data});</script> post.php <?phpob_start();var_dump($_POST);$data = ob_get_clean();$fp = fopen("textfile.txt", "w");fwrite($fp, $data);fclose($fp);?> textfile.txt array(0) {} why is the $_POST variable empty? and how would i post 2 variables like $_POST['firstname'] and $_POST['lastname'] Link to comment Share on other sites More sharing options...
JamesB Posted November 18, 2012 Report Share Posted November 18, 2012 you need to also specify the key for each value used in the data variable, eg. var data = {firstname: 'something-here',lastname: 'something-here-2'}; 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now