当我传递硬编码的URL时,它的工作正常,但是当使用其参数创建url时,它无法正常工作
var server = "localhost";
var port = "8080";
var db = "US";
var lon = "-77.092609";
var lat = "38.871256";
var epsg = "epsg:4326";
var inp= "5";
var url = '"http://'+server+':'+port+'/rest/'+db+'.json?q=travel&point='+lon+','+lat+','+epsg+'&inp='+inp+'"';
document.write(url);
xmlhttp.open("GET","http://localhost:8080/rest/US.json?q=travel&point=-77.092609,38.871256,epsg:4326&inp=5",true);//WORKS FINE
xmlhttp.open("GET",url,true);//DOES NOT WORK!!
我做错了什么?
答案 0 :(得分:0)
在字符串的开头和结尾取出双引号。
var url = 'http://'+server+':'+port+'/rest/'+db+'.json?q=travel&point='+lon+','+lat+','+epsg+'&inp='+inp;