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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:31:41+00:00 2026-06-01T23:31:41+00:00

I use JSONP on a client to get data from a server using a

  • 0

I use JSONP on a client to get data from a server using a WCF service that can return results using HTTP GET (It gets a ‘callback’ parameter which is a ‘function name’ and returns callback({data}), you know… JSONP).

Everything works, but if I enable caching (using ‘AspNetCacheProfile’)on one of the service’s operations – then something is wrong, and I’m not sure what…

The way I get the JSONP is by using a function I picked up some time ago from a question here on SO (http://stackoverflow.com/questions/2499567/how-to-make-a-json-call-to-a-url)

function getJSONP(url, success) {
  var ud = 'fc_' + + Math.floor(Math.random()*1000000),
      script = document.createElement('script'),
      head = document.getElementsByTagName('head')[0]
          || document.documentElement;

  window[ud] = function(data) {
      head.removeChild(script);
      success && success(data);
  };

  script.src = url.replace('callback=?', 'callback=' + ud);
  head.appendChild(script);
}

This creates a random id (‘fc_xxxx’) then assigns it as a function inside the window object, then use it as the ‘callback’ parameter for the url of the dynamic javascript that is injected to the document, and then the ‘ud’ function runs, removes the script and calls the ‘success’ callback function with the received data.

When using it on normal uncached operations from the service, it usually takes about 200ms to get back the response, and it works ok.
The cached responses takes ~10ms –
and I get an error that the ‘fc_XXXXX’ function is undefined.

It’s as if the response is “too fast” for it.

I also tried using jQuery.getJSON() – and, again the callback doesn’t trigger.
In all cases when I look at the network traffic in Firebug – I can see the GET request, and I can see that the right data does in fact gets returned.

Does anybody have an idea how can I make it work right with the cached responses…?

  • 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-01T23:31:42+00:00Added an answer on June 1, 2026 at 11:31 pm

    I got it! The name of the response-function is different on each call (on both my manual jsonp implementation and that of jQuery).
    The name of the function is part of the response from the server (as that’s part of how jsonp works…).
    So, if the response is a cached response – it will actually return the old name of the function (which will no longer exist on the client’s context).
    So I just need to give a constant name for the callback function in this case and it should bee fine. 🙂

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

Sidebar

Related Questions

I am trying to use JSON and HTTP client to retrieve data from a
I am using jQuery to get back some JSON data from the server. I
how can i send JSON request from blackberry application that works as client to
I am developing RESTful API for my application. All getters (that use HTTP GET)
I use json-rpc client from json-rpc.net in my windows phone application. Code: var client
I'm trying to make getJSON to use JSONP object, but I can't figure out
I work with a android device which use a WCF web service. I managed
My AJAX-enabled WCF service returns JSON using this contract, [DataContract] public class JQGridContract {
I'm trying to use AutoBean on the server and client to send and receive
I use jQuery's ajax method to make jsonp requests to my server (I make

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.