M
M
Maxim Frolov2021-09-27 08:03:44
AJAX
Maxim Frolov, 2021-09-27 08:03:44

How to Ajax load html content?

There is html code:

<div class="city_wrapper">
        <ul class="region_ul">
        </ul>
</div>


and JS Code:
$(".region_no, #select_city").click(function() {
    $.ajax({ type: "POST",url: "/ajax/",data: { "city": 'subdomains'},cache: false, success: function(data){ $(".region_ul").html(data); } });
});

It is necessary that when you click on the select button, the list was loaded into html, the question is where should I load this list. The path is specified by url: "/ajax/" i.e., this is a folder in the root of the site, if I understand correctly, then in this folder there is a city folder from data and then the subdomains file itself in which the html content for output. Made it this way, but it didn't work.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel, 2021-09-27
@Asokr

If you just need to load a list of cities, put in /ajax/city.php

echo '<li>Москва</li><li>Воронеж</li><li>Екатеринбург</li>';

And make an ajax call to the appropriate file.... /ajax/city.php

N
Nadim Zakirov, 2021-09-27
@zkrvndm

Example: The contents of the #id block will be loaded with data by reference.
$('#id').load('https://yousite.ru/test.html');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question