Я не уверен, что мой подход верен, но моя цель состоит в том, чтобы сделать запрос, и как только ответ получен, все элементы, соответствующие определенному имени класса, сохраняются, и затем текст каждого элемента изменяется на результат из ответа.
Сценарий:
$(document).ready(function() {
$("#calendarBtn").click(function() {
$("#calendar").show();
$.ajax({
url: "http://localhost:8000/calendar",
success: function(result) {
//Store elements
var elems = document.getElementsByClassName("ei_Title");
// Convert the NodeList to an Array
var arr = jQuery.makeArray(elems);
//iterate through each element
$.each(arr, function(index, val) {
//iterate through ajax response
$.each(result, function(key, value) {
console.log(key, value);
var title = (result[key].title);
//This is where I'm unsure as to how I set
the text of the element in "arr"
to the "title"
variable
});
});
}
});
});
});
HTML:
<div class="calendar_events">
<p class="ce_title"></p>
<div class="event_item">
<div class="ei_Dot dot_active"></div>
<div class="ei_Title"></div>
<div class="ei_Copy"></div>
</div>
Ответ:
{id: 6, title: "Walk the dog", date: "2018-12-05", assigned_to: "Sam", time: "11:00:00"}
assigned_to: "Sam"
date: "2018-12-05"
id: 6
time: "11:00:00"
title: "Walk the dog"