From the course: Ajax with PHP: Add Dynamic Content to Websites

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Respond with HTML partials

Respond with HTML partials

From the course: Ajax with PHP: Add Dynamic Content to Websites

Start my 1-month free trial

Respond with HTML partials

- [Narrator] In this movie, we'll write our first Ajax response using PHP. Often when responding to an Ajax request, we will want to return either simple text, or a small portion of HTML. We typically don't want to return a full HTML page. That is, everything from the beginning HTML tag, the header, the body tags, all of that. Usually what we want is just to return a small portion, a fragment of HTML which we can call a partial. So we're going to take that partial and we're going to return that back, and then we get it into our Ajax as a response we can use that bit of HTML to update a small portion of the page. The output for the response, what we're sending back to the Ajax request is just going to be text that's in our PHP page or text that we've echoed out using PHP. The same way as if we were outputting something to HTML. It works exactly the same way. You don't want to use return or anything like that, content that's on the page or that we use PHP echo to put on the page is what…

Contents