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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:51:03+00:00 2026-05-14T07:51:03+00:00

I have to write a script which will be hosted on differents domains. This

  • 0

I have to write a script which will be hosted on differents domains. This script has to get information from my server.

So, stackoverflow’s user told me that i have to use JSON-P format, which, after research, is what i’m going to do. (the data provided in JSON-P is for displaying some information hosted on my server on other website)

  1. How do I output JSON-P from my server ? Is it the same as the json_encode function from PHP

  2. How do i design the tree pattern for the output JSON-P
    (you know, like : ({“name” : “foo”, “id” : “xxxxx”, “blog” : “http://xxxxxx.com“});
    can I steal this from my XML output ? (http://bit.ly/9kzBDP)

  3. Each time a visitor browse a website on which my widget is it’ll make a request on my server, requesting the JSON-P data to display on the client side.
    It’ll increase dramatically the CPU load (1 visitor on the website who will have the script = 1 SQL request on my server to output data), so is there any way to ‘caching’ the JSON-P information output to refresh it only one or twice a day and stores it into a ‘file’ (in which extension?).

BUT on the other hand i would say that requesting the JSON-P data directly (without caching it) is a plus, because, websites which will integrates the script only want to display THEIR information and not the whole data. So, making a script with something like that:

jQuery.getJSON("http://www.something.com/json-p/outpout?filter=5&callback=?", function(data) {
................);
});

Where filter= the information the website wants to display.

  • Bonus question : do I have to use a JS framework to read JSON-P ? or JS pure without any framework to include on the page can do that ?

What do you think ?

Thank you very much
😉

  • 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-14T07:51:03+00:00Added an answer on May 14, 2026 at 7:51 am

    JSONP request

    $.ajax({
      type: "get",
      dataType: "jsonp",
      url: "mothership.com/widget_data",
      data: {whatever: "here", requested_from: "someonesblog.com" },
      cache: true,
      success: function(data, textStatus, XMLHttpRequest){
        // respond to ajax call here
    
        // debug: make sure your data is getting loaded properly
        console.log(data);
    
        // do other necessary things here
      }
    });
    

    Encode and Output JSON from server

    <?php
      header("Content-Type: application/json");
    
      # You can access data from the jQuery.ajax() call with $_GET here
    
      $data = array(
        "name" => "foo",
        "id"   => 1234,
        "blog" => $_GET["requested_from"]
      );
      echo $_GET["callback"] . "(" . json_encode($data). ");" ;
    
      # this will output something like
      # jsonp1255285823({"name":"foo","id":1234,"blog":"someonesblog.com"});
    
      exit;
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 395k
  • Answers 395k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you are using windows you might want to change… May 15, 2026 at 2:33 am
  • Editorial Team
    Editorial Team added an answer Use Response.Write(string). There are a couple of shortcuts to Response.Write… May 15, 2026 at 2:33 am
  • Editorial Team
    Editorial Team added an answer Your second code snipppet doesn't release the object you created.… May 15, 2026 at 2:33 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.