Coder Social home page Coder Social logo

backbone.nativeajax's People

Contributors

akre54 avatar florian-r avatar gaearon avatar lillywolf avatar mjeanroy avatar nikolayfrantsev avatar philippmi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

backbone.nativeajax's Issues

create and publish new version

Hi,

would you mind creating and publishing a new version of Backbone.NativeAjax so we can use the latest changes.

cheers

Call not working with POST

It looks like with POST the code is just passing the data object to the XHR which isn't actually sending the data to the server. I'm able to workaround this by adding a contentType of "application/x-www-form-urlencoded" and code like the following to the file.

  // Stringify POST query params.
  if (options.type === 'POST' && typeof options.data === 'object' && options.contentType == 'application/x-www-form-urlencoded') {
    var dataToSend = '';
    var stringifyKeyValuePair = function(key, value) {
      return value == null ? '' :
        '&' + encodeURIComponent(key) +
        '=' + encodeURIComponent(value);
    };
    for (var key in options.data) {
      dataToSend += stringifyKeyValuePair(key, options.data[key]);
    }
    options.data = dataToSend.substring(1);
  }

Am I doing something wrong here? data is a standard javascript object with key/value pairs.

      type: 'POST',
      url: 'myapiurl',
      data: data,
      contentType: 'application/x-www-form-urlencoded',
      success: function(results) {
      },
      error: function(results) {
      }

Access to HTTP headers

We recently switched from jQuery to NativeView/NativeAjax. Before the switch I was able to access the HTTP headers through the XHR object in my Backbone parse method:

parse(response, options) {
    if (options.xhr.getResponseHeader('Content-Type').includes('application/vnd.api+json')) {
        ...
    }
}

With NativeAjax, options.xhr is a Promise which resolves to the data I already have through the response parameter.

Hence, I have no possibility to access the response headers or did I miss something?

Backbone: 1.2.1
Backbone.NativeAjax: 0.3.2

Parse JSON based on accept header instead of content-type

Why does NativeAjax parse the response based on the provided accept header and only uses content-type if no custom accept header was specified?

If I provide an accept header like
application/vnd.myformat, application/json;q=0.9
and the server is unable to serve application/vnc.myformat it will fall back to application/json.
However, when the response is processed by NativeAjax, it only looks at the accept header and not on the response content type and therefore never parses JSON responses for this accept header.

Furthermore, the code only checks if the accept header starts with application/json, so if I rearrange my custom header to
application/json;q=0.9, application/vnd.myformat
it would parse the response. AFAIK the order of the MIME types is not relevant for the accept header according to the specification but NativeAjax depends on it.

"typeof Promise !== null" makes no sense

typeof Promise !== null on line 63 is not a valid check for the existence of Promise. It should be typeof Promise !== 'undefined' or something more specific to the implementation you are expecting.

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.