hey guys i have a problem when i'm trying to send two variables by ajax i did the same code w3schools used in this link http://www.w3schools.com/ajax/tryit.asp… but it only works when i use one variable only !! my code :
<script>
function showHintname() {
var ln = document.getElementById("lname").value ;
var fn= document.getElementById("fname").value ;
if (fn.length == 0) {
document.getElementById("txtHint-name").innerHTML = "";
return;
}
else {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint-name").innerHTML = xmlhttp.responseText;
}
}
//xmlhttp.open("GET", "ini/name.php?f=" + fn , true); // working
// xmlhttp.open("GET", "ini/name.php?f=" + fn &'l=' + ln , true); // not working
xmlhttp.open("GET", "ini/name.php?f=1&l=1", true); // not working
xmlhttp.send();
}
}
</script>
use this it will work
xmlhttp.open("GET", "ini/name.php?f=" + fn+ "&l=" + ln , true);
xmlhttp.open("GET", "ini/name.php?f=" + fn &'l=' + ln , true);
This statement doesn't work because the & symbol is not inside the quotes. You should also as a general practice, try to be consistent with single/double quotes. This should work
xmlhttp.open("GET", "ini/name.php?f=" + fn+ "&l=" + ln , true);
$.ajax({
method: ,
url: ,
data: { var1: data1, var2: data2 }
}, done(function(data) {
//Do some actions
});
<script>
function showHintname() {
var ln = document.getElementById("lname").value
var fn= document.getElementById("fname").value ;
if (fn.length == 0) {
document.getElementById("txtHint-name").innerHTML = "";
return;
}
else {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint-name").innerHTML = xmlhttp.responseText;
}
}
//the url
var url = "ini/name.php?f=" + fn + "&l=" + ln;
xmlhttp.open("GET", url, true);
xmlhttp.send(null);
}
}