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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:35:59+00:00 2026-05-18T10:35:59+00:00

I have no trouble making jsonp requests, however I’m unsure about setting up a

  • 0

I have no trouble making jsonp requests, however I’m unsure about setting up a web service to deliver responses in jsonp.

First, does a server need to be configured in a certain way to allow jsonp requests, or does the page just have to have the response properly formatted?

In my testing I have the following jsonp response from geonames.org (I’ve placed it a blank page on server/domain 1 with nothing else):

<?php echo $_GET['callback'];?>({"postalcodes":[{"adminName2":"Westchester","adminCode2":"119","postalcode":"10504","adminCode1":"NY","countryCode":"US","lng":-73.700942,"placeName":"Armonk","lat":41.136002,"adminName1":"New York"}]});

On server/domain 2 I’m making the following request:

$.ajax({
    // works when I make the call to geonames.org instead of domain1
    //url: 'http://www.geonames.org/postalCodeLookupJSON?postalcode=10504&country=US&callback=?',,
    url: 'http://www.domain1.com/test/jsonp.php?callback=?',
    success: function(data) {
        $('#test').html(data);
    },
});

The call works when I place the files on the same server (either domain 1 or 2) and turn it into a regular json request. What am I doing wrong?

Just to clarify: My question pertains to the page RECEIVING the request. I know the request works when I make it to geonames.org, flickr, etc… apis. However, I’m trying to set up a page to send a response. In my example I just have a blank page with hard coded jsonp. I’m not sure if I have to have some other headers on the page or have something enabled on my server.

  • 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-18T10:35:59+00:00Added an answer on May 18, 2026 at 10:35 am

    The response is wrong.

    If you have the following url:
    http://www.mydomain.com/test/jsonp.php&callback=? jQuery will replace the question mark at the end of the url with a unique string. On the serverside you have to take this string($_GET[‘callback’]) and use it as function-name in your response:

    PHP-example:

    <?php
     $object=array('postalcodes'
                      =>array(
                                array(
                                        "adminName2"  =>  "Westchester",
                                        "adminCode2"  =>  "119",
                                        "postalcode"  =>  "10504",
                                        "adminCode1"  =>  "NY",
                                        "countryCode" =>  "US",
                                        "lng"         =>  -73.700942,
                                        "placeName"   =>  "Armonk",
                                        "lat"         =>  41.136002,
                                        "adminName1"  =>  "New York"
                                       )));
    
       echo $_GET['callback'].'('.json_encode($object).')';
    ?>
    

    What happens with the response when receiving it? jQuery knows the unique string(assuming fx123456).
    jQuery will create a <script>-element with the src: http://www.mydomain.com/test/jsonp.php&callback=fx123456 . jQuery will call a on the fly created function named fx123456() . This function will return the JSON(as a object) which will be taken as data-argument of the success-function of $.ajax().

    So if you don’t use the callback-parameter provided by jQuery as functions-name inside the response, jQuery doesn’t know the name of function to call(I better say jQuery will call a function that doesn’t exist).

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

Sidebar

Related Questions

i have a little trouble while making my first play application. I got a
I'm migrating to Nhibernate 2.0 GA but have some trouble with setting cache expirations
I have being having trouble with the web server used for our intranet. It
i have used observed_field for arrays of data... but i am having trouble making
I have trouble comparing 2 double in Excel VBA suppose that I have the
I have trouble with the following piece of code. When I go through with
I have trouble using Perl grep() with a string that may contain chars that
I have trouble defining a trigger for a MySQL database. I want to change
I have no trouble building 1.35.0, as well as 1.36.0 on the timesys arm-gcc
I am developing a small windows app, but have some trouble deciding whether to

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.