I have the following code that displays a form and should be saved through Jquery .ajax () a MySQL On submitting the form in the database, I get the error SyntaxError: unexpected token N . What does this mean and how can I fix it?
HTML:
& lt; Form class = "well" id = "jquery-submit-ajax" name = "jquery-submit-ajax" method = "post" action = "ajax.php" & gt; & Lt; Div class = "floatleft" & gt; & Lt; Input type = "text" class = "span7" name = "yourName" placeholder = "your name" & gt; & Lt; / Div & gt; & Lt; Div class = "floatleft" & gt; & Lt; Input type = "text" class = "span7" name = "yourNumber" placeholder = "your number" & gt; & Lt; / Div & gt; & Lt; Input class = "btn btn-primary" type = "submit" value = "schedule" & gt; & Lt; Br / & gt; & Lt; Br / & gt; & Lt; Div class = "alert alert-hiding success" & gt; & Lt; P & gt; Form submitted successfully! Data sent is below: & lt; / P & gt; & Lt; Div id = "success-output" class = "prettyprint" & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div class = "alert alert-hide hiding" & gt; & Lt; P & gt; Error below: & lt; / P & gt; & Lt; Div id = "error-output" class = "very print" & gt; & Lt; / Div & gt; & Lt; / Div & gt;
Junkies:
& lt; Script & gt; $ ("#Jquery-submit-ajax") Submit (function (e) {var postData = $ (e.target) .serialize (); $ .ajax ({type: "POST", url: "ajax.php", data: postdata, datatype: "jason" , Before: function () {$ ('warning-error, table-success'). Hide ();}, error: function (jqXHR, text position, error, error) {$ ('warning-error') $ ('# Error-output'). $ ('Error-output'). Html (error);} success: work (data) {$ ('alert-success'). $; ('# Breakthrough-output'); Html (data);}}); Returned;}); & Lt; / Script & gt; ajax.php:
& lt; Php $ servername = "localhost"; $ Username = "user"; $ Password = "pass"; $ Dbname = "database"; // Create connection $ conn = new mysqli ($ servername, $ username, $ password, $ dbname); // Check connection if ($ conn- & gt; connect_error) {dead ("Connection failed:". $ Conn-> connect_error); } $ YourName = htmlspecialchars (trim ($ _ POST ['yourName'])); $ YourNumber = htmlspecialchars (trim ($ _ POST ['yourNumber'])); $ Sql = "Include contacts (name, number) values ('$ yourName', '$ yourNumber')"; If ($ conn- & gt; query ($ sql) === true) {"new record successfully created" echo; } Else {echo "error:" $ sql "& lt; br & gt; . $ Conn- & gt; Error; } $ Conn- & gt; Close (); ? & Gt;
I suspect that there is a NNN near pass in JSN. NaN JSON is unsupported to use to validate the JSN data passed by PostData.
No comments:
Post a Comment