Git Product home page Git Product logo

Comments (10)

ded avatar ded commented on June 2, 2024

hmm... the before send can be added.
?callback= is a JSONP thing. in which case i'd probably recommend using $.getScript

$.getScript('http://example.com/?callback=jazz');

of course we can work in some magic in $script.js to wrap it in a nice callback so you can just do this:

$.getScript('foo.js', {
  handlerName: function () {
    // done
  }
});

from reqwest.

dvv avatar dvv commented on June 2, 2024

Personally, I find reqwest interface clearer. The most confusing is type option which has completely different meanings in both flavors.

What if expose reqwest interface under different alias (say $.Ajax), and make $.ajax be a wrapper, which should take jQuery options, reduce them to reqwest options and delegate to $.Ajax, printing a warning to the console?

Not very clear, but should help initial transition, and constant warnings may eventually make people to use reqwest ;)

from reqwest.

dvv avatar dvv commented on June 2, 2024

Hi! Any progress in coping with this issue? They just consider it a stopper: jashkenas/backbone#322 (comment)

from reqwest.

beatgammit avatar beatgammit commented on June 2, 2024

I agree with @dvv in principle. I like reqwest's syntax better too.

Perhaps instead of a wrapper, there could be a compat mode: reqwest.compat('jQuery') or something that's set once.
This would bloat reqwest a little, but a few bytes never hurt anyone =D

from reqwest.

zenlor avatar zenlor commented on June 2, 2024

I came out with this to patch Spine.js:

  if (reqwest) {
    $ajax = function(params) {
      var error, success;
      params.method = params.type.toLowerCase();
      params.type = params.dataType;
      delete params.dataType;
      params.headers = {
        'Content-Type': params.contentType
      };
      if (params.success) {
        success = params.success;
        params.success = function(data) {
          return success(data, "success", this);
        };
      }
      if (params.error) {
        error = params.error;
      }
      params.error = function(data) {
        return error(data, "error", this);
      };
      return reqwest(params);
    };
  } else if (jQuery) {
    $ajax = $.ajax;
  }

I am sure it's buggy and handles only one use case.
But it's quite similar on what RightJS does with his jquerysh plugin.

from reqwest.

ded avatar ded commented on June 2, 2024

i'm starting to like the idea of calling compat('jquery') which invokes a bridge. i'll see if i can have a play with that.

from reqwest.

mattly avatar mattly commented on June 2, 2024

would a patch for a 'dataType' option (per jQuery, basically would allow sending Content-Type: application/json instead of application/x-www-form-urlencoded) be welcomed? This is an adoption-blocker for me.

from reqwest.

rvagg avatar rvagg commented on June 2, 2024

You can provide a custom Content-Type as it is, without a dataType option. This is roughly what a JSON call can look like with Reqwest:

$.ajax({
  url: '/happyPlace',
  method: 'post',
  type: 'json',
  data: JSON.stringify(happyData),
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  },
  success: onSuccess,
  error: onError
});

Reqwest has sensible defaults for Accept and Content-Type but they aren't enforced if you provide your own.

from reqwest.

mattly avatar mattly commented on June 2, 2024

Thanks, but I'm (also) working with a library that expects things to work like jQuery and take a 'dataType' option instead of specifying headers.

from reqwest.

mattly avatar mattly commented on June 2, 2024

Eh, I can override it just fine with something like:

oldajax = $.ajax;
$.ender({ ajax: function(options) {
  if (options.dataType === 'json') {
    if (! options.headers) { options.headers = {}; }
    options.headers['Content-Type'] = 'application/json';
  }
  oldajax(options)
}});

It's not ideal but it works.

from reqwest.

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.