PolymerElements / iron-ajax

Easily make ajax requests
https://www.webcomponents.org/element/PolymerElements/iron-ajax
127 stars 113 forks source link

Getting exception when using iron-ajax for sync request. #293

Open anotherapj opened 7 years ago

anotherapj commented 7 years ago

Description

The iron-ajax element is throwing script exception for sync request.

Expected outcome

The iron-ajax should complete the sync request and return the request object with response data.

Actual outcome

Getting the below exception InvalidAccessError: A parameter or an operation is not supported by the underlying object

Live Demo

NA

Steps to reproduce

1, Create iron-ajax element. 2, Set the sync property. 3, call the generateRequest() method. Below is the code(slightly modified version from app-localize-behavior) `var ajax = proto.localizationCache.ajax; if (!ajax) { ajax = proto.localizationCache.ajax = document.createElement('iron-ajax'); ajax.sync = true; }

var request = proto.__localizationCache.requests[path];
if (!request) {
    ajax.url=path;
    ajax.method= "POST";
    ajax.headers = { "Content-Type":"application/json"};
    ajax.body = this.getRequestBody();
    ajax.handleAs = "json";        
    request = ajax.generateRequest();`

The failure is happening on iron-request.html file @ send method, trying to set xhr.withCredentials = !!options.withCredentials; If I remove the above line, the request works fine.

Browsers Affected