javascript - 未捕获的语法错误 : Unexpected token < , ajax 调用

标签 javascript jquery html ajax

<script>
    (function(){
        var searchURL = 'http://en.wiktionary.org/wiki/search';
        $.ajax({
                type: "GET",
                url: searchURL,
                dataType: "jsonp",
                cache: false,
                async:false,
                success: function(responseData, textStatus, XMLHttpRequest){
                        iframe(responseData);
                    }
            });
    })();
    </script>

我将此脚本添加到我的 html 文件中,它显示以下错误,在控制台中复制粘贴该函数也显示相同的错误。

Uncaught SyntaxError: Unexpected token < 
Resource interpreted as Script but transferred with MIME type text/html

谁能帮我解决这个问题,我使用的是 Chrome 浏览器。

最佳答案

您无法通过 AJAX 请求任意页面,并且 jsonp 并不能神奇地实现这一点。您需要使用 Wiktionary API .

网址为http://en.wiktionary.org/w/api.php

$.ajax({
    url: 'http://en.wiktionary.org/w/api.php',
    dataType: 'jsonp',  // will automatically add "?callback=jqueryXXX"
    cache: true,  // the API complains about the extra parameter
    data: {  // the parameters to add to the request
        format: 'json',
        action: 'query',
        titles: 'test'
    },
    success: function(data){
        console.log(data);
    }
});

关于javascript - 未捕获的语法错误 : Unexpected token < , ajax 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16722264/

相关文章:

javascript - 在光标不移动时更改光标

javascript - 丰富的 Web 应用程序的嵌套链接(标签)的有效替代方案?

javascript - jQuery:如何检查内容是否有任何 URL

javascript - angular js ng-repeat范围内的单选按钮列表,默认选中

html - 屏幕尺寸更改时图像无响应。

javascript - 使用 HTML 输入更新数据值并更改数据数组

javascript - 在 html header 中设置 no-cache 不起作用

javascript - 如何防止停止滚动悬停 iFrame(完美滚动条)?

php - HTML 表单第二个按钮不会搜索我的数据库

html - XHTML - 添加新元素