Good day.
Just started to master the technology AJAX . Completely broke my head. I do not understand how I can properly handle the response from the server.
My function:
function email() { var res = ''; // результирующая строка - пока пустая. var elem = document.getElementById('mail'); var str = elem.value; // текст из формы. var list = str.split("\n"); // разбивка... for (var i = 0; i < list.length; i++) { str = list[i]; // пустые строки пропускаем... if (str.length < 1) continue; // проверка наличия такого емайла в базе... request = $.ajax({ type: "POST", url: "email_check.php", data: "email=" + str, success: function(request, res) { if (request == "1") { res = res + str + '(есть)' + "\n"; } else { res = res + str + '' + "\n"; } } }); } elem.value = res; } Those. I have an editable field on the page - id='mail'; . E-mail addresses are entered there, separated by a line break. Then they are divided into separate elements by the line break symbol. Next - each such separate address - I check the server request for uniqueness. If you already have one, email_check.php will return "1", if not, then "0".
My task is to get the same email list again - for those who already have it - you need to add (есть)+\n , i.e. again get the same list with line breaks and write it back into the form in the mail element.
Thanks in advance.