1

I have a checkbox on a webpage that when you click it, updates the value in the database as well as the editedBy and editedDate columns in a table in the database. I am doing the update via an ajax call to a php page. I am trying to get the updated editedDate and editedBy data in the callback on success so i can update the sorresponding span tags that hold this information. I'm trying to use jQuery to accomplish this. This is what i have so far:

var updateUserDate = function(data){
    var table = data.table;
    var rowId = data.rowId;
    var editedDate = data.editedDate;
    var editedBy = data.editedBy;
    //alert(table+' - '+rowId+' - '+editedDate+' - '+editedBy);
    $('"#'+table+' .row'+rowId+' .newEditedDate"').html('"'+editedDate+'"');
}
var submitDataCheckbox = function(target){
    var project = target.attr('project');
    var tableName = target.attr('table');
    var rowId = target.attr('rowId');
    var checkboxValue = (target.attr('checked'))?true:false;
    $.ajax({
        type: 'GET',
        url: '/checklistpost.php?projectId='+project+'&table='+tableName+'&rowId='+rowId+'&value='+checkboxValue,
        success: function(data){
            updateUserDate(data);
        },
        error: function(){
            alert('There was an error submitting data to the database.');
        },
        dataType: 'json'
    }); 
}

The checklistpost.php page takes the variables that are in the query string and posts them to the database. It also then puts the variables in an array which is then encoded in json so that i have a json object to work with. Basically, i am trying to take that json object that gets called back and use it to update the span as mentioned above. When i have used an alert() inside of the updateUserDate function before to verify that i can see the variables and they all have the right data (you can see the code i used to do this is commented out). However, whenever i try and use the variables with jQuery as you see on the 6th line of the code. It doesn't do anything. BTW, The jQuery code that should be output based on what is written above should look like this $("#tableName .row1 .newEditedDate").html("April 14, 2011 @ 5:15pm") What am i missing? Thanks in advance for any help!

1
  • Are you using the jQuery validate plugin anyhwere? Some plugins like old versions of jQuery validate can modify the global ajaxSetup() and cause this sort of thing to fail. Commented Apr 14, 2011 at 22:16

2 Answers 2

3

Your selector is broken, you've got extra quotes in there:

'"#' + table+' .row' + rowId + ' .newEditedDate"'

should be:

'#' + table + ' .row' + rowId + ' .newEditedDate'

So:

// you're surrounding editedDate with extra quotes too, or is that intentional?
$('#' + table + ' .row' + rowId + ' .newEditedDate').html(editedDate);
Sign up to request clarification or add additional context in comments.

1 Comment

Oh brother! Guess i have been staring at this for too long and didn't see the obvious...fail haha. Thanks so much for your help! +1 for you!
1

Why are you using single and double quotes? The command you are passing to jQuery will evaluate to this:

$('"#tableName .row1 .newEditedDate"').html('"April 14, 2011 @ 5:15pm"')

instead of this:

$("#tableName .row1 .newEditedDate").html("April 14, 2011 @ 5:15pm")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.