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 6914947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:24:48+00:00 2026-05-27T09:24:48+00:00

I want to have a static website uploaded on an external server that will

  • 0

I want to have a static website uploaded on an external server that will try to get JSON data from localhost:3000 (a server program will already be running on the user’s computer).

I’m trying to do this with jQuery like this:

$.getJSON("http://localhost:3000/page", function(data){
    // process data...
});

Why am I getting cross-origin policy errors and how can I stop them? I thought accessing JSON data was supposed to negate those cross-site errors?

UPDATE 1

I have just tried the JSONP with callback as suggested but here’s a weird issue: If I add a script tag that points to the localhost:3000/page URL, the callback is loaded and the data is displayed properly when the page is done loading, but this is not what I am aiming for.

If I try the same thing using the $.getJSON method, I still get the same error as before:

XMLHttpRequest cannot load http://localhost:3000/page. Origin http://localhost is not allowed by Access-Control-Allow-Origin..

  • 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-05-27T09:24:49+00:00Added an answer on May 27, 2026 at 9:24 am

    Interesting idea!

    But localhost is a totally different domain from somewebsite.com. So the same origin policy applies. You need either:

    • JSONP Which means the server on localhost needs to support wrapping the JSON in a custom callback
    • CORS Which allows true cross domain ajax, but lots of extra header fuzting is required on both ends of the request.

    JSONP is probably the easiest to pull off. From the docs for $.getJSON():

    If the URL includes the string “callback=?” (or similar, as defined by
    the server-side API), the request is treated as JSONP instead. See the
    discussion of the jsonp data type in $.ajax() for more details.

    Your localhost server then simply needs to use that callback parameter that jQuery will pass in. Meaning that instead of simply rendering this:

    <%= jsonString() %>
    

    The local server should render something more like this:

    <% if (params.callback) { %>
      <%= params.callback %>(<%= jsonString %>);
    <% } else { %>
      <%= jsonString %>
    <% } %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have many mp3 files stored on my server already from a static website,
If I have a collection of static constants that I want to declare centrally
we have a static, non-wicket CMS website and we want to include a dynamic
I have client that built a website that is part static html and part
What I want is, opening a Link from a Website (from HtmlContent) and get
I am designing a website and I want to have a static menu at
I have some static images in a folder on my IIS 6-based website that
We have a website that we have been able to translate static texts to
I have a website and want to step over from MySql to SqlServer. In
I have a static website served up by nginx right now, and I want

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.