So, I have a really simple form on a website that is completely designed to load its pages on AJAX. The only way to work with this form is to have it do the AJAX magic, so I started doing it. I had a testing form, so I knew that it all worked.
Here's the javascript for my form. The variable "fullpath" just tells me which page is currently loading, all pages are stored in the local folder "pages". It serializes the form and sends it to the server with some debugging alerts.
$(document).ready(function() { $("#regForm").submit(function(event) { alert($(this).serialize()); $.post("pages/" + fullpath, $(this).serialize(), function(data){ alert(data); }); return false; }); });
Here the form itself
<form name="input" id="regForm"> <div class="form-field"><label>Username</label> <input type="text" name="username"/></div> <div class="form-field"><label>Password</label> <input type="password" name="password"/></div> <div class="form-field"><label>Confirm Password</label> <input type="password" name="password2"/></div> <div class="form-field"><label>Screen Name</label> <input type="text" name="screenname"/></div> <div class="form-field"><label>Email Address</label> <input type="text" name="address"/></div> <div class="form-field"><label>Group</label> <select name="usergroup"> <option value="0">Superuser</option> <option value="1">Admin</option> <option value="2">Moderator</option> <option value="3">Advmember</option> <option value="4">Member</option> <option value="5">Guest</option> </select> <br /> <label>Submit: </label><input type="submit" value="Submit" /> </div> </form>
And here are some PHP that I put at the top of the page
print_r($_POST);
So, I fill out the form with some fictitious information, and I click submit. All data is displayed using
alert($(this).serialize());
And then the call will succeed, and I will see the loaded form with
alert(data);
But, when I ask to print the $ _POST array in PHP, that’s all I get
Array ()
So jQuery sends the data, they return the page, but for some reason the POST variables fail. Anyone want to lend a hand?
source share