I\'m using jQuery to post a form to a php file, simple script to verify user details.
var emailval = $(\"#email\").val();
var invoiceIdval = $(\"#invoiceId\"
application/x-www-form-urlencoded
There's your answer. It's getting posted, you're just looking for the variables in $_POST array. What you really want is $_REQUEST. Contrary to the name, $_POST contains input variables submitted in the body of the request, regardless of submission method. $_GET contains variables parsed from the query string of the URL. If you just want submitted variables, use the $_REQUEST global.
If you expect to be receiving file uploads, than you want to create a new array including the contents of $_FILES as well:
$arguments = $_REQUEST + $_FILES;
I had a case where I was using jQuery to disable all the inputs (even the hidden ones I wanted) just before using jQuery to submit the form. I changed my jQuery to only disable the "button" type inputs and now the hidden vars are posted when the form is submitted! It seems that if you set a hidden input to disabled its values aren't posted with the form!
Changed:
$('input').attr('disabled',true);
to:
$('input[type=button]').attr('disabled',true);
$.post()
passes data to the underlying $.ajax()
call, which sets application/x-www-form-urlencoded
by default, so i don't think it's that.
can you try this:
var post = $('#myForm').serialize();
$.post("includes/verify.php", post, function(data) {
alert(data);
});
the serialize()
call will grab all the current data in form.myForm
.
I tried the given function from Owen but got a blank alert as well. Strange but i noticed it would output a query string and return a blank alert. Then i'd submit again and it would alert with correct post values.
Also had the field names set in the html using the id attribute (which was how it was done in a jquery tutorial I was following). This didn't allow my form fields to serialize. When I switched the id's to name, it solved my problem.
I ended up going with $.ajax after all that since it did what I was looking for.
I got bitten by the same issue, and I find the solution Owen gives not appropriate. You're serializing the object yourself, while jQuery should do that for you. You might as well do a $.get() in that case.
I found out that in my case it was actually a server redirect from /mydir to /mydir/ (with slash) that invalidated the POST array. The request got sent to an index.php within /mydir
This was on a local machine, so I couldn't check the HTTP traffic. I would have found out earlier if I would have done that.