manolo / gwt-polymer-elements

Polymer Web Components for GWT. A collection of Material Design widgets for desktop and mobile.
Apache License 2.0
155 stars 49 forks source link

ironAjax setHeaders not work #119

Closed fizzi closed 6 years ago

fizzi commented 8 years ago

JSONObject openAmUser = new JSONObject(); openAmUser.put("X-OpenAM-Username",new JSONString("xxxxxx")); openAmUser.put("X-OpenAM-Password",new JSONString("xxxxxx")); openAmUser.put("x-requested-with",new JSONString("XMLHttpRequest"));

    openAmAjax.setHeaders(openAmUser.getJavaScriptObject());
    openAmAjax.setContentType("application/json");
    openAmAjax.generateRequest();
manolo commented 7 years ago

It's not a problem on gwt-polymer-elements, but in the way iron-ajax checks whether a value is a javascript Object.

Since GWT creates new objects in the sandboxed $wnd iframe via the JavaScriptObject.createObject() method, those objects are not instanceof Object in the application window.

As a workaround, create your headers using any of these ways:

  @JsMethod(namespace = JsPackage.GLOBAL, name = "Object")
  static native JavaScriptObject createObject();

  static native JavaScriptObject createObject() /*-{
    return $wnd.Object();
  }-*/;

And set the headers in this way:

   JavaScriptObject openAmUser = createObject();
   Polymer.property(openAmUser, "X-OpenAM-Username", "xxxxxx");
   Polymer.property(openAmUser, "X-OpenAM-Password", "xxxxxx");
   Polymer.property(openAmUser, "x-requested-with", "XMLHttpRequest");

 ajax.setHeaders(openAmUser);
manolo commented 7 years ago

Reported issue to polymer : https://github.com/PolymerElements/iron-ajax/issues/246 Reported issue to gwtproject : https://github.com/gwtproject/gwt/issues/9464

manolo commented 6 years ago

fixend