我想將文本框「郵編」中的數據添加到URL「VALUE1」和「VALUE2」中。我甚至不能向你展示任何例子,因爲我甚至不知道從哪裏開始。在發佈之前編輯AJAX調用URL
<input type="text" name="postcode" placeholder="Postcode" ><br>
<button type="button" onclick="loadDoc()">Get Postcode</button>
<p id="Addresses">No Postcode</p>
<script>
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
document.getElementById("Addresses").innerHTML = xhttp.responseText;
}
};
xhttp.open("GET", "https://api.getaddress.io/v2/uk/VALUE1&VALUE2", true);
xhttp.send();
}
</script>
我怎麼
你要找的字符串連接的奇觀。 – SLaks
您還需要轉義該值。 – SLaks
什麼是「VALUE1」和「VALUE2」?他們都是'郵政編碼'輸入的價值嗎? –