Skip to content
Advertisement

unable to pass 2 parameters in url using javascript and ajax function [closed]

var ans = document.getElementById("str").value;
function load_questions($questionno)
{
    document.getElementById("current_que").innerHTML=questionno;
    
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            if(xmlhttp.responseText=="over") {
                window.location="result.php";
            }else{
                document.getElementById("load_questions").innerHTML = xmlhttp.responseText;

                load_total_que();
            }
        }
    };
    var PageToSendTo = "load_questions.php?";
    var VariablePlaceholder = "questionno=";
    var MyVariable = questionno;
    var VariablePlaceholder2 = "ans="; 
    var MyVariable2 = ans;
    var UrlToSend = PageToSendTo + VariablePlaceholder + MyVariable + VariablePlaceholder2 + MyVariable2;

    xmlhttp.open("GET", UrlToSend, false);
    xmlhttp.send();
}

its taking only one parameter i am not a pro out here but was facing this issue i want 2 parameters to one is getting passed its questionno other i want is document.getElementById(“str”).value; this value in the url to compare using $_GET in php

help me out with this thank you!!

Advertisement

Answer

“&” symbol is missing.

Try this:

var UrlToSend = PageToSendTo + VariablePlaceholder + MyVariable + '&' + VariablePlaceholder2 + MyVariable2;
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement