V Posted July 22, 2010 Share Posted July 22, 2010 I'm having a go at this for hours.. I'm trying to send some data from a link to a script but the "<a href>" id isn't being sent. The js is, $(function() { $(".add_item").click(function() { var id = $(this).attr("id"); var name = $(this).attr("name"); var dataString = 'id='+ id ; if (name=='new') { $.ajax({ type: "POST", url: "add_item.php", data: dataString, cache: false, success: function(msg){ alert( "Data Saved: " + msg ); } }); } }); }); the code <div class="green_button"><a href="" class="add_item" id="<?php echo $item_name; ?>" name="new">Add Item</a></div> and the script, require_once('functions.php'); session_start(); if (isset($_SESSION['valid_user'])) { //create short variable name $username = $_SESSION['valid_user']; $item_name = $_POST['id']; $item_name = mysql_escape_String($id); do_html_header('Adding Item'); $connection = dbConnect(); $sql = "INSERT INTO user_items (username, item_name, item_date) VALUES ('$username', '$item_name', NOW())"; $result = $connection->query($sql) or die(mysqli_error($connection)); } else { echo "Access Denied"; } do_html_footer(); It inserts the username and date into the the user_items table but the ID from the link "id=something" isn't being passed, however it shows in the HTML source. I also used firebug to check any js errors and didn't find any. What's even stranger to me, it doesn't work in Firefox, nothing is being added into the DB. I'm not sure what I'm doing wrong.. Can anyone spot a flaw? Quote Link to comment Share on other sites More sharing options...
V Posted July 22, 2010 Author Share Posted July 22, 2010 Ok I figured it out $item_name = mysql_escape_String($id); didn't pass the ID name. As for Firefox, I wasn't logged into my site on that browser... I just have one question. Using cache: false, in the Jquery ajax.. is that a good or bad thing? Quote Link to comment 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.