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

  • Home
  • SEARCH
  • 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 9003971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:47:38+00:00 2026-06-16T00:47:38+00:00

I have problems with receiving json through ajax, the error is below. According to

  • 0

I have problems with receiving json through ajax, the error is below. According to the information I’ve found so far regarding the error this seems to be some kind of cross domain issue, but I have no idea of what that means and how to solve it.

There may be an issue with the response header (I have created the API myself and have no experiences since before), however a 200 OK is received if accessing the url directly in the browser.

If accessing the url directly in the browser valid json is shown, so that shouldn’t be the problem.

How can this be solved?

Note: The url goes to an Apache server, not a file that has been the case for 95% of the questions here on Stack that I’ve read about the issue.

Error in inspector:

XMLHttpRequest cannot load http://localhost/api/v1/products?_=1355583847077.
Origin null is not allowed by Access-Control-Allow-Origin.
Error: error 

The code:

    $.ajaxSetup ({
      url: "http://localhost/api/v1/products", // <--- returns valid json if accessed in the browser
      type: "GET",
      dataType: "json",
      cache: false,
      contentType: "application/json"
    })
    $.ajax({
        success: function(data){

            console.log("You made it!");
        },
        error: function(xhr) {
           console.log("Error: " + xhr.statusText);
       }
    }).done(function(data){
        console.log(data);
    })

Params

_ 1355583610778

Headers

Response Headers:

Connection  Keep-Alive
Content-Length  3887
Content-Type    application/json
Date    Sat, 15 Dec 2012 14:50:53 GMT
Keep-Alive  timeout=5, max=100
Server  Apache/2.2.14 (Unix) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l PHP/5.3.1 mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By    PHP/5.3.1

Request Headers:

Accept  application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language sv-SE,sv;q=0.8,en-US;q=0.5,en;q=0.3
Connection  keep-alive
Host    localhost
Origin  null
User-Agent  Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:17.0) Gecko/17.0 Firefox/17.0

Response

Nothing here…

  • 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-16T00:47:39+00:00Added an answer on June 16, 2026 at 12:47 am

    Try and implement some form of JSONP mechanism. If you’re using PHP it could be something as simple as this…

    /* If a callback has been supplied then prepare to parse the callback
     ** function call back to browser along with JSON. */
    $jsonp = false;
    if ( isset( $_GET[ 'callback' ] ) ) {
        $_GET[ 'callback' ] = strip_tags( $_GET[ 'callback' ] );
        $jsonp              = true;
    
        $pre  = $_GET[ 'callback' ] . '(';
        $post = ');';
    } //isset( $_GET[ 'callback' ] )
    
    /* Encode JSON, and if jsonp is true, then ouput with the callback
     ** function; if not - just output JSON. */
    $json = json_encode( /* data here */ );
    print( ( $jsonp ) ? $pre . $json . $post : $json );
    

    All this would do is check for a $_GET var called callback, and then wrap the output in a function call – taking the $_GET['callback'] name as a function name.

    Then your AJAX call becomes something like this…

    $.ajax({
      type: 'GET',
      url: '/* script here */ ', 
      data: /* data here - if any */,
      contentType: "jsonp", // Pay attention to the dataType/contentType
      dataType: 'jsonp', // Pay attention to the dataType/contentType
      success: function (json) {
        /* call back */
      }
    });
    

    When jQuery is given 'jsonp' as a dataType/contentType it will take care of providing a callback function name for you – and setting the callback function up etc; meaning you don’t have to do anything really!

    From the jQuery documentation:

    “jsonp”: Loads in a JSON block using JSONP. Adds an extra “?callback=?” to the end of your URL to specify the callback. Disables caching by appending a query string parameter, “_=[TIMESTAMP]”, to the URL unless the cache option is set to true.

    Source

    In closing; JSONP is going to be your best bet – I’ve included PHP code in the off chance that your server side script is using PHP; if not then the principles are the same. The jQuery/client side stuff stays the same regardless of server side technologies though. (in general)

    Good luck 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problems trying to load png file into my application. It seems to
This seems to be quite a common theme and a few people have given
I am receiving JSON string response from my WCF service. I wanna parse this
I have been receiving errors when trying to save and run this Python 3.1
I'm receiving a strange error from my call to query() the database. This normally
I have problem with receiving an image over TCP socket [.net 4.0] Server: Socket
I have strange problem with receiving data from socket. On client im using air
i have an application in which i am receiving WALLPAPER_CHANGED broadcast. the problem is
i have problems with a really basic thing. setting properties after instantiation a UIViewController-
I have problems with creating a simple Group-Box-Control via CreateWindowEx. The font-size/-style of its

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.