These are chat archives for canjs/canjs

18th
Sep 2017
abdulsmrehman
@abdulsmrehman
Sep 18 2017 10:36

Hi All,

I need to pass a vendor specific "ContentType" is the request header using can-connect/data/url modle. But i found out that can-connect/data/url/findContentType supports only "application/json" and "application/x-www-form-urlencoded" other vendor types are not supported and default "application/json" is getting passed.

Is there a way to pass vendor specific "ContentTypes" .
canjs/can-connect#351

Jeroen Cornelissen
@jeroencornelissen
Sep 18 2017 11:23
@abdulsmrehman You could use $.ajaxSetup({contentType: ‘whatever’})
And then set can-connect to use $.ajax
Ivo Pinheiro
@ivospinheiro
Sep 18 2017 14:21

@abdulsmrehman, using the @jeroencornelissen input I would create a function like this:

const ct = function(ct) {
  return function() {
    let args = arguments ? arguments[0] : {};
    return $.ajax(assign(args, { contentType: ct }));
  };
};

and then on can-connect:

connect([
  require("can-connect/data/url/url")
],{
  url: "/things",
  ajax: ct("application/type")
});

Instead of configuring the application type on ajaxSetup

Ivo Pinheiro
@ivospinheiro
Sep 18 2017 14:35
Maybe it makes sense to be added as a configuration to the can-connect url behavior
abdulsmrehman
@abdulsmrehman
Sep 18 2017 14:47
Thanks @ivospinheiro and @jeroencornelissen . With the above input provided i was able to resolve my problem .
Jeroen Cornelissen
@jeroencornelissen
Sep 18 2017 14:48
:+1: