You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Elementor表单集成机场API自动选择功能时的特殊字符错误及代码问题求助

Elementor表单集成机场API自动选择功能时的特殊字符错误及代码问题求助

大家好,我正在用Elementor自定义代码搭配Elementor表单,想实现一个调用API的机场自动选择功能。目前我的代码如下,但遇到了<、&、>这类特殊字符相关的错误,麻烦各位帮忙看看,非常感谢!

我的代码如下:

const accessKey = 'xxxx';
const    url=`https://app.goflightlabs.com/retrieveAirportaccess_key=${accessKey}&amp;query=${encodeURIComponent(query)}`;

document.addEventListener('DOMContentLoaded', function() {
    const inputField = document.querySelector('#departure');
    const suggestionBox = document.createElement('div');
    suggestionBox.classList.add('suggestion-box');
    inputField.parentNode.appendChild(suggestionBox);

inputField.addEventListener('input', async function() {
    const query = inputField.value;
    return;  // Start suggesting after 2 characters

    try {
        const response = await fetch(`[url]?query=${query}`);
        const suggestions = await response.json();

        suggestionBox.innerHTML = '';  // Clear previous suggestions

        suggestions.forEach(suggestion  {
            const suggestionItem = document.createElement('div');
            suggestionItem.classList.add('suggestion-item');
            suggestionItem.innerText = suggestion;
            suggestionItem.addEventListener('click', function() {
                inputField.value = suggestion;
                suggestionBox.innerHTML = '';
            });
        suggestionBox.appendChild(suggestionItem);
        });
        } catch (error) {
        console.error('Error fetching suggestions:', error);
        }
        });

        document.addEventListener('click', function(event) {
            if (!suggestionBox.contains(event.target) &amp;&amp; event.target !== inputField) {
            suggestionBox.innerHTML = '';
        }
    });
});

我希望能从API获取机场建议,并将其用于表单的选择功能中。

备注:内容来源于stack exchange,提问作者William Charlesworth-jones

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 09:00:31