Note that there are some explanatory texts on larger screens.

plurals
  1. POSubmit form using ajax
    text
    copied!<p>I'm trying to submit values to a database using jquery. I'm new to ajax but I'm required to do it with ajax.</p> <p>This is what I've done so far my php code is</p> <pre><code> function insertSeries() { $options = array( 'user' =&gt; $_POST['user'], 'email' =&gt; $_POST['email'], 'summary' =&gt; $_POST['summary'], 'due_date' =&gt; $_POST['due_date'], 'problem_type' =&gt; $_POST['problem_type'], 'status' =&gt; $_POST['status'] ); $sql = "insert into ticket_summary('user','email','summary','due_date','problem_type','status') Values (?,?,?,?,?,?)"; $result = mysql_query($sql, $options) or die('Could not insert data'); } </code></pre> <p>My html code is </p> <pre><code> &lt;?php include 'eric_api.php'; ?&gt; &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;&lt;/title&gt; &lt;script src="js/jquery.js"&gt;&lt;/script&gt; &lt;script src="js/api_calls.js"&gt;&lt;/script&gt; &lt;link rel="stylesheet" href="css/normalizer.css" /&gt; &lt;link rel="stylesheet" href="css/style.css" /&gt; &lt;/head&gt; &lt;body&gt; &lt;div class="wrapper"&gt; &lt;h1&gt;Ticketing System&lt;/h1&gt; &lt;div&gt; &lt;div id="ticket_form_wrapper"&gt; &lt;form id="insert_ticket" method="post" action=""&gt; &lt;p&gt; &lt;label for="user"&gt;User&lt;/label&gt; &lt;br /&gt; &lt;input type="user" id="user" class="post_fields" /&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="email"&gt;Email&lt;/label&gt; &lt;br /&gt; &lt;input type="email" id="email" class="post_fields" /&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="summary"&gt;Summary&lt;/label&gt; &lt;br /&gt; &lt;input type="summary" id="summary" class="post_fields" /&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="due_date"&gt;Due Date&lt;/label&gt; &lt;br /&gt; &lt;input type="due_date" id="due_date" class="post_fields" /&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="problem_type"&gt;Problem Type&lt;/label&gt; &lt;br /&gt; &lt;input type="problem_type" id="problem_type" class="post_fields" /&gt; &lt;/p&gt; &lt;p&gt; &lt;label for="status"&gt;Status&lt;/label&gt; &lt;br /&gt; &lt;input type="status" id="status" class="post_fields" /&gt; &lt;/p&gt; &lt;p&gt; &lt;input type="submit" id="submit" value="Submit" /&gt; &lt;input type="button" onclick="window.location='index.php'" value="Go to List"/&gt; &lt;div class="form_result"&gt; &lt;/div&gt; &lt;/p&gt; &lt;/form&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>And here's my ajax using jquery</p> <pre><code>$('#insert_ticket').submit(function(e){ var postData = $(this).serialize(); alert(postData); $.ajax({ type: 'POST', url: 'http://localhost/api/eric_api.php?q=insertseries', data: postData, success: function(response){ $('#insert_ticket').find('.form_result').html(response); }, error: function(){ alert('error'); } }); e.preventDefault(); }); </code></pre> <p>I don't know what I'm doing wrong. Any help would be greatly appreciated</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload