小编beg*_*rog的帖子

对于我的提取请求,我不断收到错误“字符串与预期模式不匹配”

对于我的提取请求,我不断收到错误“字符串与预期模式不匹配”​​。我在这里和其他论坛上看到有些人有类似的问题,但无法确定问题所在。如果有人有任何建议,请告诉我。

function showRecipes(){
            const ingredients = document.getElementById('ingredients').value.replace(/\s/g, "");
            const meal = document.getElementById('meal').value;
            const display = document.getElementById('display'); //Where results will go

            let url = 'http://www.recipepuppy.com/api/';
            url += `?i=${ingredients}&q=${meal}`;

            fetch(url, { mode: "no-cors"})
                .then(response => {
                    response.json()
                        .then(data => {
                            data.results.forEach(recipe => {
                                const container = document.createElement('div');
                                container.setAttribute('class', 'container');

                                const h1 = document.createElement('h1');
                                h1.textContent = recipe.title;

                                const p = document.createElement('p');
                                p.textContent = recipe.ingredients;

                                display.appendChild(container);
                                container.appendChild(h1);
                                container.appendChild(p);
                            })
                        })
                        .catch(err => {
                            console.log(err);
                        })
                })
                .catch(err => {
                    console.log('ERROR: ' + err);
                }) …
Run Code Online (Sandbox Code Playgroud)

html javascript api

10
推荐指数
2
解决办法
2万
查看次数

标签 统计

api ×1

html ×1

javascript ×1