Vue-resource: xhr: {withCredentials: true} is not work on v.0.93 but work on v.0.7.4

Created on 11 Jul 2016  路  9Comments  路  Source: pagekit/vue-resource

xhr: {withCredentials: true} is not work on v.0.93 but work on v0.7.4

Most helpful comment

wow, after use

Vue.http.options.credentials = true;

It's works well!

All 9 comments

The option has changed, now its just Vue.http.post('/url', {...}, {credentials: true})

@steffans
Although i use the latest API to turn on the credentials option, it still can not transfer CORS cookie.
Using JQ, I can transfer that. So it's not my CORS cookie setting problem.
If you can do that in v0.9.3?

@steffans btw, I have reset the default header within the 'POST' method, avoiding using OPTION method.

@Rockergmail you can use
Vue.http.options.xhr = {credentials: true} in global

@lh8725473 when using v0.9.3 API, can you transfer the CORS cookies ?

@Rockergmail yes

@lh8725473 there's only one setting in https://github.com/vuejs/vue-resource/blob/2f951df7261a5bd940438addf83b2a13de06c873/src/http/client/xhr.js#L39,
and, after trying I don't think Vue.http.options.xhr = {credentials: true} is useful.

wow, after use

Vue.http.options.credentials = true;

It's works well!

That option doesnt work on 0.9.3

var createCORSRequest = function(method, url) {
  var xhr = new XMLHttpRequest();
  if ("withCredentials" in xhr) {
    // Most browsers.
    xhr.open(method, url, true);
  } else if (typeof XDomainRequest != "undefined") {
    // IE8 & IE9
    xhr = new XDomainRequest();
    xhr.open(method, url);
  } else {
    // CORS not supported.
    xhr = null;
  }
  return xhr;
};

var url = 'CORS URL HERE';
var method = 'POST';
var xhr = createCORSRequest(method, url);

xhr.onload = function() {
  // Success code goes here.
};

xhr.onerror = function() {
  // Error code goes here.
};

xhr.withCredentials = true;
xhr.send();

that code working - instead of vue-resource

Was this page helpful?
0 / 5 - 0 ratings

Related issues

briward picture briward  路  4Comments

gbhlwm picture gbhlwm  路  5Comments

laizhenhai88 picture laizhenhai88  路  4Comments

ayyobro picture ayyobro  路  3Comments

V-Tom picture V-Tom  路  3Comments