我试图在单击按钮时解析 XML 文档树。XML 文件在查找函数中获取,该函数采用 2 个值(“id”和“shipping”)并将其附加到适当的 URL 上,然后 JSON.parse 将相关数据附加到适当的文本字段“地址”中。我需要使用此解析的结果动态填充另一个输入行,但 URLFetch 仅在 code.gs 端可用。有没有办法将数组从 gs 端传递到我的 javascript 端,或者我最好的选择是 XMLHttpRequest 函数?我在js端尝试过url fetch,还有一个新函数“httpGet”URLFetch 函数:document.getElementById('lookup').addEventListener('click',patientLookup); function personLookup(){ var patient = document.getElementById('id').value; var shippingStyle = document.getElementById('shipping').value; var address = document.getElementById('address'); var url = "someurl?patientID=" + patient; var shippingAddress = UrlFetchApp.fetch(url,{'muteHttpExceptions':true}); Console.log(shippingAddress) var addressData = JSON.parse(shippingAddress.getContentText()); var shipAdd = addressData.Address; var city = addressData.City; var state = addressData.State; var zip = addressData.Zip; address.value = shipAdd + "," + city + "," + state + "," + zip; };HttpGet 函数: function httpGet(theUrl) { var xmlHttp = new XMLHttpRequest(); xmlHttp.open( "GET", theUrl, false ); // false for synchronous request xmlHttp.send( null ); return xmlHttp.responseText; } 显然错误的是,URLFetch 仅在 gs 端支持,然后 httpGet 函数无法正常工作,我也不像我对 fetch 函数那样熟悉这样的函数。
添加回答
举报
0/150
提交
取消