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

6
  • 6
    You're requesting jsonp, but receiving HTML. The jsonp isn't a magic solution that lets you get any data from any domain. The response needs to be a jsonp response. Commented May 23, 2013 at 19:28
  • 3
    en.wiktionary.org/wiki/search does not render data in JSONP format. It is just an HTML page. So when trying to parse the HTML as JSON, you're getting an error because the first character is a <. What are you trying to accomplish? Commented May 23, 2013 at 19:28
  • is there any alternate way we can get data from wiktionary using js Commented May 23, 2013 at 19:30
  • This is asked fairly frequently. I'd suggest searching for how to get data from a different domain. Ultimately, if there's no server-side support for cross-domain requests, you'll need a proxy to make the request for you. Commented May 23, 2013 at 19:32
  • 1
    You should probably have a look at mediawiki.org/wiki/API and mediawiki.org/wiki/API:Data_formats Commented May 23, 2013 at 19:33

1 Answer 1

3

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);
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.