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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:13:25+00:00 2026-05-12T12:13:25+00:00

When I use getJSON in JQuery to an external domain the request that is

  • 0

When I use getJSON in JQuery to an external domain the request that is made does not include cookies for that domain. I’m using this for my analytics script that I am writing and I need to set a cookie on the external domain where the script is running so I can track unique visitors.

The files

domain1.com/website.html

    <script src="http://domain2.com/tracker.js"></script>

domain2.com/tracker.js

//Get information about the user
info = "(here's some things about the user)";

//Send data using JSON
$.getJSON("http://domain2.com/getdata.php?"+info,
            function(data){}
         );

domain2.com/getdata.php

 /******
  * Code to save data and stuff
  *******/

//Get the current cookie (if any).
$current_tid = $_COOKIE['tID'];

//checks if the cookie is a string of 50 characters
if (strlen($current_tid)==50){
  $TrackerID = $current_tid; //If the cookie already have a unique string, then use it!
} else {
  $TrackerID = random_gen(50); //Generates a new random string with 50 characters
}

//Set cookie "tID" with the unique variable $TrackerID
setcookie("tID",$TrackerID,time()+60*60*24*365);

So, the thing is that when the user loads website.html on server1, the user also loads tracker.js on server2 which sends some data with JSON to getdata.php. However, the script does not send cookies and getdata.php will generate a new string every time the script is loaded.

Is there any way to send cookies using JSON?

  • 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-12T12:13:25+00:00Added an answer on May 12, 2026 at 12:13 pm

    You should use JSONP instead of regular JSON:

    In you script you should add this:

    $.getJSON("http://domain2.com/getdata.php?callback=?&"+info,
        function(data){}
    );
    

    And instead of the original JSON, you PHP script should return your JSON in the format:

    header("Content-Type: text/javascript");
    $callback = $_GET["callback"];
    print "$callback(";
    // Code to produce the JSON output as normal
    print ");";
    

    More info on JSONP and jQuery is available here.

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

Sidebar

Related Questions

'''use Jython''' import shutil print dir(shutil) There is no, shutil.move, how does one move
Use case: A does something on his box and gots stuck. He asks B
We use a data acquisition card to take readings from a device that increases
Use case: 3rd party application wants to programatically monitor a text file being generated
I use Firebug and the Mozilla JS console heavily, but every now and then
I use rsync to synchronize files to Windows clients in a server agnostic way.
I use emacs to edit my xml files (nxml-mode) and the files were generated
I use the VS2008 command prompt for builds, TFS access etc. and the cygwin
I use a stream reader to import some data and at the moment I
We use QuickBooks for financial management, and feed it from a variety of sources.

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.