Answer the question
In order to leave comments, you need to log in
JS or JQuery function to check $_POST global array variables?
Task:
If 2 forms of feedback. One consists of 2 fields, the other of 4. There is a js script that ajax-th sends data from the form. In the ajax script, you need to write a check to see if there is a certain variable in the global POST array in order to separate the sending of the first form data from the second.
Script code:
document.getElementById('feedback-form').addEventListener('submit', function(evt){
var http = new XMLHttpRequest(), f = this;
evt.preventDefault();
http.open("POST", "http://zero-waste.loc/wp-content/themes/zerowaste/d_contacts.php", true);
http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
if()
{
http.send("nameFF=" + f.nameFF.value + "&telFF=" + f.contactFF.value + "&messageFF=" + f.messageFF.value);
}
else
{
http.send("nameFF=" + f.nameFF.value + "&telFF=" + f.telFF.value );
}
http.onreadystatechange = function() {
if (http.readyState == 4 && http.status == 200) {
alert(http.responseText +', Ваше сообщение получено.\nНаши специалисты ответят Вам в течении 2-х дней.\nБлагодарим за интерес к нашей фирме!');
}
}
http.onerror = function() {
alert('Извините, данные не были переданы');
}
}, false);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question