JQuery AJAX Result

I am having a problem calling ajax using jQuery. I send the information to the server and return the data as expected. The type of data I return is html. Using firebug, if I am a data console, it shows an object with all my tags. I want to manipulate the form of the returned data, but when I try to console.log the form, I get an empty object. What am I doing wrong? Here is my code:

$.post('add', {'ajax':true}, function(data){  
  var $data = $(data);  
  console.log($data.find('form'));  
});
+3
source share
3 answers

Check out this example . It works as expected. Maybe your answer is not very good?

+1
source

I usually prefer the following syntax for selecting elements from an HTML response:

$.post('add', {'ajax':true}, function(data){
  var myform = $('form', data); 
  console.log(myform);  
});

$() .

+1

:

var $data = $(data);

, html, , .

0

Source: https://habr.com/ru/post/1778152/


All Articles