I am trying to make something where you can post, and with jQuery it submits (no refresh or parsing via another page) and inserts the data into the DB. The code I am using for the jQuery is in my <head> and this is the code:
Opinion. All you did was blame Democrats for everything.
You offered nothing but a hit piece to support your pro Trump, anti union right wing ideology.
By the sounds of that wall of Fox News propaganda gibberish attacking the Democratic Party you've already had plenty of "juices" flowing this morning.
You've ruined what could have been a productive comment thread.
Question
Shazer2
I am trying to make something where you can post, and with jQuery it submits (no refresh or parsing via another page) and inserts the data into the DB. The code I am using for the jQuery is in my <head> and this is the code:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script> <script type="text/javascript" > $(function() { $(".submit").click(function() { var np = $("#np").val(); $.ajax({ type: "POST", url: "inc/ajax.php", data: np, success: function(){ $('.success').fadeIn(200).show(); $('.error').fadeOut(200).hide(); } }); } return false; }); </script>I then have the following in ajax.php and I am 100% certain it's in the correct directory.
<?php /** * @author Shannon * @copyright 2011 */ session_start(); include ("connect.php"); $user = $_SESSION['username']; $np = $_POST['np']; $np = mysql_real_escape_string($np); mysql_query("INSERT INTO `posts` (user, np) VALUES ('$user', '$np')") or die(mysql_error()); ?>That is all correct too, but it just doesn't seem to insert into the database. If anyone has an idea why, please post a reply.
Link to comment
https://www.neowin.net/forum/topic/990268-jquery-submitting-a-form/Share on other sites
17 answers to this question
Recommended Posts