Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7915493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:28:24+00:00 2026-06-03T14:28:24+00:00

In this John Resig article , he’s is dealing with a dictionary-sized list of

  • 0

In this John Resig article, he’s is dealing with a dictionary-sized list of words with javascript, and he’s loading the content via ajax from a CDN.

The words are loaded in with newlines separating the words. Then he says cross domain fails:

There’s a problem, though: We can’t load our dictionary from a CDN!
Since the CDN is located on another server (or on another sub-domain,
as is the case here) we’re at the mercy of the browser’s cross-origin
policy prohibiting those types of requests. All is not lost though –
with a simple tweak to the dictionary file we can load it across
domains.

First, we replace all endlines in the dictionary file with a space.
Second, we wrap the entire line with a JSONP statement. Thus the final
result looks something like this:

dictLoaded(‘aah aahed aahing aahs aal… zyzzyvas zzz’);

This allows us to do an Ajax request for the file and have it work as
would expected it to – while still benefiting from all the caching and
compression provided by the browser.

So, if I’m reading this correctly, simply adding his method dictLoaded('original content') around the original content alone causes the ajax request to not fail.

Is that (turning it into a function + param) really all it takes? and why does JSONP solve the problem of cross domain access restriction?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:28:26+00:00Added an answer on June 3, 2026 at 2:28 pm

    the <script> tags can load any JS file from anywhere (even cross domain). The nice thing that comes with it is that the code inside that script is also executed, therefore, a method of bypassing cross-domain restrictions.

    The problem is, when the code gets executed, it’s executed in the global scope. so having this code:

    var test = 'foo'
    

    will create a test variable in the global scope.

    To mitigate this, you use enclose the reply in a function. This is the “P” in “JSONP” which means “padding”. This encloses your reply in a function call.

    So if your foreign script has:

    myFunction({
        test : 'foo'
    });
    

    It calls myFunction and passes an object with test key which has value foo. The receiving function would look like:

    function myFunction(data){
        //"data.test" is "foo"
    }
    

    Now we have successfully bypassed the cross-domain restriction. The essential parts needed are:

    • the receiving function (which can be dynamically created and discarded after use)
    • the “padded” JSON reply
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was reading John Resig's Secrets of JavaScript Ninja and saw this code: function
So I've seen this post on JavaScript Micro-Templating by John Resig and I have
This is from John Resig`s Learning Advanced JavaScript #35 http://ejohn.org/apps/learn/#35 , called What happens
I m reading John Resig s Learning Advanced JavaScript http://ejohn.org/apps/learn/#10 and came across this
Hey everyone, this is #23 from John Resig Advanced JavaScript http://ejohn.org/apps/learn/#23 , called What
John Resig’s Simple Javascript Inheritance: http://ejohn.org/blog/simple-javascript-inheritance/ I tried to do such thing: var SomeClass
I watched John Resig's Best Practices in JavaScript Library Design presentation; one slide suggested
I am a newbie to java script and currently reading John Resig's Pro javascript
I decided to try out JavaScript genius John Resig's simple JavaScript inheritance as detailed
I'm reading the John Resig blog about the Strict Mode in javascript, but i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.