Hey, I've got a bunch of form data that goes into a JSON object that I throw to a PHP script with a post call, but all the post variables throw undefined errors in the PHP script. Not sure why.. if(!firstNameError && !lastNameError && !handleError && !passwordError && !acceptError){ //there are no errors so toss the data to serverside script then database. var regJSON = { "firstName":"BOB", "lastName":"DYLAN", "handle":"DILLY", "email":"DILLYSON", "password":"DILPASS", "accept":"YUP"}; $.ajax({ tpye: "POST", dataType: "html", data: regJSON, url:"../admin/scripts/php/registration.php", success: function(data){ alert(data); } }); } Code (markup):
Well... Without the processing php file, and the errors it's throwing, this one's gonna be hard to solve...
Sorry about that, lol. I thought there was no typos in that script, so assumed it was an Ajax code problem.. $firstName = $_POST['firstName']; $lastName = $_POST['lastName']; $handle = $_POST['handle']; $email = $_POST['email']; $password = $_POST['password']; $accept = $_POST['accept']; echo "<p>The Data!</p>"; PHP:
I just installed Firebug. Not sure hot to get the full potential out of it yet, but did get some error... SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data - jquery.min.js(line 4). As a secondary question. I'm not sure why it's involving a file called jquery.min.js. I installed jquery myself into a file called jquer.js in my dir tree. I sourced that file in the top of my index page, above my other script using jquery, on the same page my forms on.... I think even if I don't source my jquery file I still have jquery functionality throughout my scripts...seems to be global, but have no clue why, lol.
Is that really all you have for the php file? Also, where are the errors showing up, in your alert? Or are you getting php error messages in your error_log? More info please!
Okay, I solved this using Firebug. I saw there was a query sting, so I realized I may need to be using $GET variables...works like a charm now.
You also had a typo in your original ajax call, see your first post.... it says: tpye: "POST" Code (markup): Could be why it wasn't workin
Since you're using jQuery, I'm also a little confused as to why you don't just do: $.post('../admin/scripts/php/registration.php',$('#id_of_form').serialize(),function(data) { // do stuff here })
Didn't know the function existed... That typo is why. I thought I was being smart, turns out I had a typo. Found it at home. The default type is $_GET. I understand Jquery wanting to make their function work no matter what, but extracting my misspelled parameter and sticking in their default is a sloppy choice.. It should have thrown an error....If I hadn't of stumbled across the typo at home I would have never known it was there... Except for of course you guys.