简体   繁体   English

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

[英]Uncaught syntax error: Unexpected token < , ajax call

<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>

I added this script to my html file and it is show the following errors, copy pasting the function in console is also showing the same errors. 我将此脚本添加到了html文件中,并显示了以下错误,复制粘贴到控制台中的函数也显示了相同的错误。

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

could anyone help me resolve this issue, I am using Chrome brower. 任何人都可以帮助我解决此问题,我正在使用Chrome浏览器。

You can't request arbitrary pages via AJAX, and jsonp doesn't magically make that work. 您不能通过AJAX请求任意页面,并且jsonp不能神奇地实现这一目的。 You need to use the Wiktionary API . 您需要使用Wiktionary API

The URL is http://en.wiktionary.org/w/api.php . 该URL是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);
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM