0

I cannot use value div name in fourth-last line

I want to use div name in Ajax function in $("divname").html(data);

$('.edit').click(function() {
    var object = $(this);
    var rowvalue = object.attr('id');
    var rowvalue_array = rowvalue.split('_');
    var id = rowvalue_array[1];
    var comment = $('#comment_'+id).val();
    var divname = '#'+id;
    var varData = 'id='+id+'&comment='+comment;
    console.log(varData);
    $.ajax ({
        type: "POST",
        url: "edit_field.php",
        data: varData,
        success: function(data) {
            $("divname").html(data);
        }
    });
    return false;   
});
1
  • Thanks Srivi. Can you help above problem. Commented Jan 23, 2014 at 4:10

4 Answers 4

2

Use the following code..

$.ajax ({
               type: "POST",
               url: "edit_field.php",
               data: varData,

               success: function(data) {
                    $(divname).html(data);
               }
         });
Sign up to request clarification or add additional context in comments.

Comments

0

Please replace your line as below :

$(divname).html(data);

remove quata (")

divname is variable or you can use as below :

$("#"+id).html(data);

1 Comment

Worked Vijay ji! Thanking you
0

Try this:

$.ajax ({
               type: "POST",
               url: "edit_field.php",
               data: varData,

               success: function() {
                    $("divname").html($(this).data);
               }
         });

Comments

0

Why are you accessing the element by id when u have the element.....try

$(object).html(data);

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.