-2
我有一個調用API的下拉選擇的問題。它將允許用戶在URL如www http://www.staynsurf.com/modules/listing/address_description.php?時從數據庫中選擇?....但如果URL沒有www,則會出現錯誤。 (即http://staynsurf.com/modules/listing/address_description.php?...)。跨域JavaScript/AJAX問題
<script language="javascript" type="text/javascript">
function getXMLHTTP() {
var xmlhttp=false;
try{
xmlhttp=new XMLHttpRequest();
}
catch(e) {
try{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1){
xmlhttp=false;
}
}
}
return xmlhttp;
}
function getState(countryId) {
var strURL="http://www.staynsurf.com/findState.php?country="+countryId;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('statediv').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
作品非常感謝! – pmanning