0

Using jQuery, I tried to load a definition file from Dictionary.com's API:

var tmpWord = "hello";    
jQuery.ajax({
            type: "GET",
            url: "http://api-pub.dictionary.com/v001?vid=<MYKEY>&q="+tmpWord+"&site=dictionary",
            dataType: ($.browser.msie) ? "text/xml" : "xml",
            success: function(xml) {
                console.log($(this).text());
            }
        });

(NOTE: I've replaced my API key with the thing on purpose so you lot don't steal it :P)

Anyway, for some reason, this will return a result in IE but not Firefox :'( and this is the same even if I force dataType: 'xml' Any ideas gurus?

Cheers.

Neuro

3 Answers 3

3

Isn't this a cross domain scripting issue? That's not allowed. IE gives you the option to override the settings based on your security level however firefox won't allow cross domain scripting

Wikipedia Article:Cross-site scripting

Maybe i have the context wrong but that's my 2 cents.

Also why would you do this on the client if anyone can just read your ApiKey in the source?

Sign up to request clarification or add additional context in comments.

Comments

1

Are you trying to just access the XML as a text string?

If so, this should do the trick on the xml object

string = new XMLSerializer().serializeToString( xml )

Comments

0

Ok, so I managed to sort this by using the following statement:

window.dict_api_callbacks = function(theObj) {
        window.result = theObj.primaries[0].entries[1].terms[0].text;
    }

    $.getScript("http://www.google.com/dictionary/json?callback=dict_api_callbacks&q="+tmpWord+"&sl=en&tl=en&restrict=pr%2Cde&client=te", function() { 
    //code
});

...and then returning window.result as the item's text. I gave up on the Dictionary.com API - it seems rough and awkward when compared to generic Google "unofficial" API.

Thank you anyway - I have distributed points.

N

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.