1

This website (http://www.thekatespanos.com/scrabble-score-calculator/) has a button where a user can validate the word they have typed in against some online dictionaries. I understand how the code works in terms of the jQuery code, but I don't fully get how it does what it does as it pulls in data from other webpages..

Here is an example:-

$.ajax({
        url: 'http://dictionary.reference.com/browse/' + word,
        type: 'GET',
        error: function() {
            $('#validationDC').html('<span class="invalid">error loading from</span> <a target="_blank" href="http://www.dictionary.reference.com/browse/' + word + '">Dictionary.com</a>.');   
        },
        success: function(res) { 
            var definition = $(res.responseText).find('.results_content').html();
            if (definition) {
                $('#validationDC').html('<span class="word valid">' + word + '</span> is a valid word according to <a target="_blank" href="http://www.dictionary.reference.com/browse/' + word + '">Dictionary.com</a>.');
                //$('#definitionDC').html(definition);
            }
            else {
                $('#validationDC').html('<span class="word invalid">' + word + '</span> is not a valid word according to <a target="_blank" href="http://www.dictionary.reference.com/browse/' + word + '">Dictionary.com</a>.');
            }
        },
        complete: function() {
            $('.loading').remove();
        }
    });

This code sends a jQuery ajax request to dictionary.reference.com to validate the word entered on the application and parses the returned data to identify whether or not the word is valid.

How is this possible, given the same origin policy? Can somebody explain as I feel I'm missing something.

Mat Richardson
  • 3,576
  • 4
  • 31
  • 56
  • possible duplicate of [Ways to circumvent the same-origin policy](http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy) – Quentin Mar 04 '13 at 20:30
  • Possibly, but there's a lot going on there. I would appreciate a reason as to why this code in particular works - I'm fairly new to Javascript so anything more specific would be really helpful.. – Mat Richardson Mar 04 '13 at 20:34
  • They run it through a proxy that brings back JSONP. – Quentin Mar 04 '13 at 20:35
  • How did you find this? Where in the code would I find evidence that this is the case? Apologies for noob questions, but I'm still learning. – Mat Richardson Mar 04 '13 at 20:38
  • I hit view source, then Ctrl+F, then ` – Quentin Mar 04 '13 at 20:39
  • OK..I understand how to find and read the code (that's how I came up with the question in the first place).. What I don't get it how this works. If the code does run through a proxy to return JSONP, where in the code do I find this? – Mat Richardson Mar 04 '13 at 20:41
  • I've also looked and cannot find the code mentioned by Quentin. It does appear that jQuery is referenced at least 3x, though... – cssyphus Mar 04 '13 at 20:48
  • I think it's the 'jquery.xdomainajax.js' file that does the trick - but i've not gone past there to see *how* it does it, sorry... :) – Grim Mar 04 '13 at 21:10

0 Answers0