Coder Social home page Coder Social logo

Comments (7)

jdsharp avatar jdsharp commented on July 21, 2024

Hi Zach,

Can you submit a pull request with a failing test for this?

  • jd

from amplify.

zachleat avatar zachleat commented on July 21, 2024

I didn't have time to do this, but here's the workaround I used:

amplify.request.cache.jsonpToLocalStorage = function(resource, settings, ajaxSettings, xhr)
{
    var ajaxSettingsCopy = $.extend({}, ajaxSettings);
    ajaxSettingsCopy.url = ajaxSettingsCopy.url.replace(/\&?callback=[^&]*\&?/gi, '');

    return amplify.request.cache.localStorage(resource, settings, ajaxSettingsCopy, xhr);
};

and then use the jsonpToLocalStorage type instead of localStorage.

from amplify.

genereddick avatar genereddick commented on July 21, 2024

I'm having the same issue (I think). In making a jsonp request with ?callback=? a unique callback id is generated by jQuery, which creates a unique cache name property ("myurl.com?callback=111111") based on the entire url including the callback id.

On a follow on request a new unique callback id is generated, thus a new cache name (myurl.com?callback=222222") and thus the earlier cache is ignored and a new http request is made instead.

from amplify.

elijahmanor avatar elijahmanor commented on July 21, 2024

This is still and issue. I am about to record about this feature for my 1st Pluralsight course due on Saturday. Anyone have a pull request for it?

I'm a little swamped at the moment. I did do a PR for mockjax yesterday, but don't think I'll get around to a PR on this one.

from amplify.

dcneiner avatar dcneiner commented on July 21, 2024

I was looking into it this morning and since jQuery supports a number of options, the fix will have to account for the following:

  1. Pay attention to the dataType, and only attempt this fix if its set to jsonp
  2. Correctly look to the jsonp option to see if we should look for callback= or something else.
  3. Look to jsonpCallback to see the name of callback to remove from the url
  4. Make sure cache is set to true on AJAX Settings, else a _=TIMESTAMP will also be added to the URL

Number 4 should already be handled due to the way amplify will just pass on the cache setting to $.ajax and it will not be false in the case of someone wanting to cache a JSONP request.

from amplify.

rniemeyer avatar rniemeyer commented on July 21, 2024

Was looking into this one for a few minutes and found one interesting thing to note: jQuery 1.8+ tries to safely reuse the jsonp callback names whenever possible. So, in some simple examples to reproduce this issue, the caching worked properly as the URL does not change (it does each time prior to 1.8).

from amplify.

nicholascloud avatar nicholascloud commented on July 21, 2024

I have created a pull request to fix this issue.

from amplify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.