开发者

jQuery ajax callback not firing jQuery code

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 tabl开发者_JS百科e = 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!


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);


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")

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜