我正在嘗試使用sepomex API?(針對墨西哥)在 corvid by wix 的一個網站上根據郵政編碼輸入自動填充城市和州字段,該網站基于 javascript,但我認為該行有問題json.response[0]["ciudad"]。$w.onReady(function () {? ? $w("#input1").onInput(() =>{? ? let zipcode = $w("#input1").value;? ? $w("#input2").value = "";? ? $w("#input3").value = "";? ? if (zipcode.length === 5) {? ? ? ? let apiUrl = "";? ? ? ? apiUrl = "https://api-sepomex.hckdrk.mx/query/info_cp/";? ? ? ? ? ? fetch(apiUrl + zipcode, {method: 'get'})? ? ? ? ? ? .then((httpResponse) => {? ? ? ? ? ? ? ? if (httpResponse.ok) {? ? ? ? ? ? ? ? ? ? return httpResponse.json();? ? ? ? ? ? ? ? }? ? ? ? ? ? ? ? else{? ? ? ? ? ? ? ? ? ? return Promise.reject("fetch was not successful")? ? ? ? ? ? ? ? }? ? ? ? ? ? })? ? ? ? ? ? .then((json) => {? ? ? ? ? ? ? ? console.log(json);? ? ? ? ? ? ? ? let response = json.response;? ? ? ? ? ? ? ? $w("#input10").value = json.response[0]["ciudad"];? ? ? ? ? ? ? ? $w("#input11").value = json.response[0]["estado"];? ? ? ? ? ? ? ??? ? ? ? ? ? ? ? $w("#text148").collapse();? ? ? ? ? ? })? ? ? ? ? ? .catch(() =>{? ? ? ? ? ? ? ? $w("#text148").expand()? ? ? ? ? ? })}})我無法顯示任何數據 API 上有輸出[? ? {? ? ? ? "error": false,? ? ? ? "code_error": 0,? ? ? ? "error_message": null,? ? ? ? "response": {? ? ? ? ? ? "cp": "44110",? ? ? ? ? ? "asentamiento": "Vallarta Poniente",? ? ? ? ? ? "tipo_asentamiento": "Fraccionamiento",? ? ? ? ? ? "municipio": "Guadalajara",? ? ? ? ? ? "estado": "Jalisco",? ? ? ? ? ? "ciudad": "Guadalajara",? ? ? ? ? ? "pais": "México"? ? ? ? }? ? }]
使用 Sepomex API 根據輸入的郵政編碼自動填充州和城市
波斯汪
2023-07-20 16:39:48