Q695 Posted May 13, 2015 Share Posted May 13, 2015 Working from this code: https://github.com/FREE-FROM-CMS/form/blob/master/Handler/engine.js function process_form(page_in, page_out){ $("form#register").submit(function() { var mydata = $("form#register").serialize(); alert(mydata); // it's only for test $.ajax({ type: "POST", url: page_in, data: mydata, success: function(response, textStatus, xhr) { alert(page_out); }, error: function(xhr, textStatus, errorThrown) { alert("error"); } }); return false; }); } How do I pass all the data to my generic data receiver at page_in taken from:https://github.com/FREE-FROM-CMS/form/blob/master/Handler/register.html <script type="text/javascript" src="forms\engine.js"></script> <form id='register'> User ID:<br> <input type='text' name='user' placeholder='User ID'><br> E-mail Address:<br> <input type='email' name='email' placeholder='E-mail Adress'><br> Password:<br> <input type='password' name='pw1' placeholder='Password'><br> Password Verification:<br> <input type='password' name='pw2' placeholder='Password Verification'><br> <input type='button' value='Register' onclick='process_form(\"testing/data_passing.php\", \"forms/login.php\")'> </form> No data seems to be sent to the server, and it doesn't seem to ge triggering a generic receiver also as shown here:https://github.com/FREE-FROM-CMS/form/blob/master/Handler/php/data_passing.php <?php ob_start();// start creating data object to be inserted to client echo"GET:"; print_r($_GET); echo" <p>POST:"; print_r($_POST); $output = ob_get_contents();//sets data output for database ob_end_clean(); require_once"../secure/db_conn.php"; $sql="INSERT INTO `database`.`test` (`data`) VALUES (:data);"; $q = $conn->prepare($sql); $q->execute(array(':data'=>$output)); When I just load the page part 3 does work generically, or with data. Quote Link to comment https://forums.phpfreaks.com/topic/296276-jquery-serialization-of-form/ Share on other sites More sharing options...
CroNiX Posted May 13, 2015 Share Posted May 13, 2015 What does your browsers console say about the ajax requests? Are they being sent to the correct URL? Your code shows you pass the url to the function so we can't see how the url is constructed. Quote Link to comment https://forums.phpfreaks.com/topic/296276-jquery-serialization-of-form/#findComment-1511725 Share on other sites More sharing options...
Q695 Posted May 13, 2015 Author Share Posted May 13, 2015 The console.log error is: Uncaught SyntaxError: Unexpected token ILLEGAL It's currently on my testing server, so NO, you can't see it, but I can tell you it's in the engine.js . Quote Link to comment https://forums.phpfreaks.com/topic/296276-jquery-serialization-of-form/#findComment-1511776 Share on other sites More sharing options...
fastsol Posted May 13, 2015 Share Posted May 13, 2015 Take a look at this, might lead you somewhere. http://stackoverflow.com/questions/12719859/no-visible-cause-for-unexpected-token-illegal This line I would personally use var mydata = $(this).serialize(); // OR var mydata = $(this).serializeArray(); I recently found the serializeArray() to be more handy, especially when you need/want to add hidden values to the posting array, like 'ajax' => true. So then the receiving php can know if the form was posted via ajax or not. Yes I know it's not foolproof on that, so I always make my form work with or without ajax. Quote Link to comment https://forums.phpfreaks.com/topic/296276-jquery-serialization-of-form/#findComment-1511806 Share on other sites More sharing options...
Q695 Posted May 17, 2015 Author Share Posted May 17, 2015 I still can't seem to figure out the form submitter, can you please rewrite the form submitter to help me just "plop" it into engine.js? Quote Link to comment https://forums.phpfreaks.com/topic/296276-jquery-serialization-of-form/#findComment-1512055 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.