How to output the response HTML data by a jQuery AJAX request?

In a jQuery AJAX request, you can output the response HTML data using the .html() method. For example, if you make an AJAX request to a URL and want to output the response HTML data to a div with the ID myDiv, you can use the following code:

$.ajax({
  url: 'example.com',
  success: function(response) {
    $('#myDiv').html(response);
  }
});

Watch a course Learn object oriented PHP

You can also use the .text() method if you want to output the response as plain text instead of HTML.

$.ajax({
  url: 'example.com',
  success: function(response) {
    $('#myDiv').text(response);
  }
});

Note that the above examples are using the shorthand method $.ajax and the success callback, you can also use the .done() method to handle the success callback, you can check the jQuery documentation for more details about the different ways to handle the ajax requests.