jquery/php AJAX request/response gets updated and printed but need edit and delete
Results 1 to 3 of 3

Thread: jquery/php AJAX request/response gets updated and printed but need edit and delete

  1. #1
    Senior Member
    Join Date
    Aug 2009
    Posts
    363

    jquery/php AJAX request/response gets updated and printed but need edit and delete

    I have an AJAX request in jquery that posts todo items to mysql.
    I have the rows displaying from the database and I have the form input working but
    I don't know how to do the delete and edit functions.
    I realize I need an id on each row for SQL to know which row to
    delete from MySQL. I added the database id field to the mysqli query.
    Now the id field got added to the AJAX response.
    I don't want it printing to the web page for the user to see it.
    How can I access it while hiding it on each row so that I can input the id when I want to either delete it or edit that row?
    The AJAX response sends all 4 fields in the response in firebug but
    I am still only printing the 3 fields out on the page. See demo page.
    janisrough.dyndns.biz/todo1.html

    This is my delete.php handler.

    PHP Code:


    require_once('global.inc.php');    
        
    $mysqli = new mysqli($dbhost,$dbuser$dbpass$dbname,$dbport);

    if (
    $mysqli->connect_error) {
        die(
    'Connect Error (' $mysqli->connect_errno ') '
                
    $mysqli->connect_error);
    }



    $sql "DELETE  FROM task WHERE id = 
    "
    .$mysqli->real_escape_string($_POST['id'])."";

    $result $mysqli->query($sql);

    $result->close();

    }
    //end i
        
    $mysqli->close();


    this is my Jquery function to delete the checked rows.
    Code:
    $('#response tbody').on( 'click', 'tr', function () {
    		  var tr = this;
    
    		  $.ajax( {
    		    type:"POST",
    		    url: 'ajax/delete.php',
    		    data: '',
    		    success: function () {
    		      t.fnDeleteRow( tr );
    		    }
    		  } );
    		} );
    What goes in the data line? THANKS,

  2. #2
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,353
    Quote Originally Posted by jrough View Post
    I don't want it printing to the web page for the user to see it.
    Why?

    Quote Originally Posted by jrough View Post
    How can I access it while hiding it on each row so that I can input the id when I want to either delete it or edit that row?
    Either you include the ID in the HTML, or you don't. You can't "hide" it while also trying to use it.

    As such, I'd say you simply need to add the ID inside each checkbox's value attribute. That way, when the form is submitted, you simply send the array of ID values that corresponds to the boxes checked.

  3. #3
    Senior Member
    Join Date
    Mar 2009
    Location
    Canada
    Posts
    794
    I agree with Brad; there's really no reason to "hide" the ID. It's not like the user can really do anything with it anyway, if he or she even notices it.
    Prison of Mirrors
    Declare variables, not war.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •