How to pass a string in url in Javascript?

Viewed 133

I'm trying to make an application that accesses different sites inside of an iframe from a private JSON dns server. I have completed the main code, but now I am trying to make it able to be accessed through the url. (Ex. https://thissite.info?url='test.json'&dnsserver='https://thissite.info') I also want it to default to a value if the variable is not defined in the url. For this, I'm using the following code:

  function setup(){
  var dns = document.getElementById("dns");
  var urlbar = document.getElementById("urlbar");
  var frame = document.getElementById("viewport");
  if (typeof url === "undefined") {
    url = 'Welcome Page URL Here';
  } else {
    urlbar.value = url;
  }
    if (typeof dnsserver === "undefined") {
    dnsserver = 'Default Server Here';
  } else {
    dns.value = dnsserver;
  }
  var xmlhttp = new XMLHttpRequest();
       xmlhttp.onreadystatechange = function() {
         console.log(this.status)
         if(this.readyState == 4 && this.status == 200){
           var response = JSON.parse(this.responseText);
           frame.src=response;
           console.log("Request Completed with 200");
       };
         if(this.readyState == 4 && this.status == 404){
           console.log("Website Not Found");
           frame.src='404.html'
       };
       }
      xmlhttp.open("GET",dnsserver + url + '.json', true);
      xmlhttp.send();
      console.log("Request Sent");
}

But even if I pass the vars in the URL, it doesn't accept it.

1 Answers
<script type="text/javascript"> $(function () { $("#btnQueryString").bind("click", function () { var url = "Page2.htm?name=" + encodeURIComponent($("#txtName").val()) + "&technology=" + encodeURIComponent($("#ddlTechnolgy").val()); window.location.href = url; }); }); </script> <input type="button" id="btnQueryString
Related