ssuperczynski
ssuperczynski

Reputation: 3426

AJAX request - can't get div content

This is part of my AJAX request. It works fine - sending code to index.php But when I would like get some content (div id="editor") from response I'm getting only something like that [object Object]

$.ajax({
      url: 'index.php',
      type: 'GET',
      data: {
         content: code
      },
      success: function(data){
          alert($('#editor'));
      }

When I change function to:

success: function(data){
          alert(data);
     }

I am getting whole source code of page

Upvotes: 1

Views: 1764

Answers (2)

susie derkins
susie derkins

Reputation: 584

Depending on what you're trying to get out of div, try

alert($('#editor').text());

or

alert($('#editor').html());

Upvotes: 1

locrizak
locrizak

Reputation: 12279

You need to change the scope of where jQuery is searching. (which is the second parameter of a jQuery selector and by default 'document').

alert($('#editor',data));

Also, you are currently getting [object Object] because alert cannot split out the object as a sting without a little help. try console.log($('#editor',data)) or alert($('#editor',data).html())

Upvotes: 5

Related Questions