Well, I do not understand what is happening. I am trying to transfer form data to my PHP script from a simple jQuery script, but for some reason when I try to access $ _POST the PHP data says $ _POST is empty?
Here we go, so I have the following jQuery and php scripts
JQuery
var post = $('#cform').serialize(); console.log("POST DATA: " + post); $.post(action, post, function(data){ document.getElementById('message').innerHTML = data; $('#message').slideDown('slow'); $('#cform img.contact-loader').fadeOut('slow',function(){$(this).remove()}); $('#submit').removeAttr('disabled'); if(data.match('success') != null) $('#cform').slideUp('slow'); });
Php
$fname = $_POST['fname']; $lname = $_POST['lname']; $email = $_POST['email']; $phone = $_POST['phone']; $comments = $_POST['comments'];
The var message console log looks like this
POST DATA: fname=Daniel&lname=Jarvis&email=test%40gmail.com&phone=4444444444&comments=hello
And var_dump $ _POST says it
array(0) { }
I do not know why this gives me so many problems, so any help would be greatly appreciated.
PS I also tried just doing this for post data, but it still didn't work.
var post = {fname: $('#fname').val(), lname: $('lname').val(), ...}
The .log console looked like this:
{fname: "Dan", lname: "Jarvis", ...}
But when I var_dumped the $ _POST variable, it still said
array(0) { }