未捕获的语法错误:意外的令牌< ,ajax电话

时间:2013-05-23 19:26:38

标签: 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浏览器。

1 个答案:

答案 0 :(得分:3)

你不能通过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);
    }
});
相关问题