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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:07:55+00:00 2026-05-23T16:07:55+00:00

I want to use this api that returns the place matching a zipcode e.g.

  • 0

I want to use this api that returns the place matching a zipcode

e.g. for zip 11233

http://postnummersok.se/api?q=11233

I call it with a user input value like this but the result does not parse, how can I troubleshoot, is it even getting the callback? My firebug shows no js errors.

$('#zip').live("keyup",function () {
    var zip = this.value.replace(/ /g,'');
    if(zip.length > 4) {
        var url = 'http://postnummersok.se/api?q=' + zip;
        $.getJSON(url, function(data) {
            $('#result').html(data);
        });
    } else {
         $('#result').html('to short');
    }
});
  • 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-23T16:07:55+00:00Added an answer on May 23, 2026 at 4:07 pm

    I assume the document your code is in is not on http://postnummersok.se. If it isn’t, you’re running into the Same Origin Policy, which doesn’t (normally) allow ajax requests to cross origins.

    If this is a publicly-available service, they probably support JSON-P, which is not subject to the SOP. jQuery also supports it, so it may be as easy as changing your code from this:

    $.getJSON(url, function(data) {
        $('#result').html(data);
    });
    

    to this

    $.ajax({
        url:      url,
        dataType: "jsonp",
        success:  function(data) {
            $('#result').html(data);
        }
    });
    

    More in the $.ajax docs.


    Update: Noticed when commenting on another answer that you’re dynamically creating a query string, but not encoding the parameter. If zip contains any characters that have to be URL-encoded, your URL will be messed up. Whenever creating query strings, you have to use encodeURIComponent:

    var url = 'http://postnummersok.se/api?q=' + encodeURIComponent(zip);
    

    …or just pass an object with key/value pairs to jQuery, which will serialize them correctly for you. Here’s what that would look like, modifying my ajax call above:

    $.ajax({
        url:      'http://postnummersok.se/api',
        data:     {q: zip},
        dataType: "jsonp",
        success:  function(data) {
            $('#result').html(data);
        }
    });
    

    Update 2: I got curious, and yes, you are allowed to use this service, and yes it uses JSON-P. From http://postnummersok.se/:

    API

    Vi har ett rest-api tillgängligt för alla.
    Skicka din sökfråga till http://postnummersok.se/api med parametern q som antingen är ett postnummer eller en ort. Svaret kommer som ett JSON-objekt. Callback-parametern heter callback.

    …which Google translates as

    API

    We have a residual-api available to all.
    Send your query to http://postnummersok.se/api with parameter q which is either a postcode or place. The answer comes as a JSON object. The callback parameter named callback.

    However, the service is broken and returning invalid JSON-P replies. If you send it

    http://postnummersok.se/api?callback=myCallback&q=721+06

    …the response is

    myCallback(["V\u00c4STER\u00c5S"])myCallback(null)
    

    …where it should be

    myCallback(["V\u00c4STER\u00c5S"])
    

    (Possibly with a ; at the end.)

    So I’d drop them a note about the bug if I were you.

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

Sidebar

Related Questions

I want to use this pure HTML/CSS template for my ASP.NET website: http://sub3.tanguay.de I
I found this open-source library that I want to use in my Java application.
My use case is this, I want to call out to a webservice and
I want to use a temp directory that will be unique to this build.
I'm trying to use a super simple API from is.gd: http://is.gd/api.php?longurl=http://www.example.com Which returns a
I have a c++ header file containing a class. I want to use this
Consider: print $foo, AAAAAAAA, $foo, BBBBBBBB; Let's say I want to use this code
I want to use google chrome as a control. I think Enso does this
I already started this in javascript so I don't want to use jquery but
I have markup like this: <p>one two three four</p> And I want to use

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.