简体   繁体   中英

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.

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.

You can't request arbitrary pages via AJAX, and jsonp doesn't magically make that work. You need to use the Wiktionary API .

The URL is 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);
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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