开发者

Send XML using XMLHttpRequest using GWT

Currently I use the JavaScript code to send XML data in GWT开发者_Python百科. Is there an easier way to send them?

 sendRequest.addClickHandler(new ClickHandler() {

      @Override
      public void onClick(ClickEvent event) {
        // RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
        // ItemExtension client = ProxyFactory.create(ItemExtension.class, "http://localhost:8081");

        sendXMLFFI(restInput.getText());

 protected native void sendXMLFFI(String text)
  /*-{
    var xmlhttp=false;

    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
      try {
      xmlhttp = new XMLHttpRequest();
      } catch (e) {
      xmlhttp=false;
      }
    }

    if (!xmlhttp && window.createRequest) {
      try {
          xmlhttp = window.createRequest();
        } catch (e) {
          xmlhttp=false;
        }
    }

    xmlhttp.open("POST", "./REST/Items",true);
    xmlhttp.setRequestHeader("Content-Type", "application/xml")
    xmlhttp.send("<?xml version='1.0' encoding='UTF-8'?>\n\n"+ 
           "<item barcode='111'><name>Foo</name><quantity>100</quantity></item>");
  }-*/;


RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, "./REST/Items");
rb.setHeader("Content-Type", "application/xml");
rb.sendRequest("<?xml version='1.0' encoding='UTF-8'?>\n\n"+  
    "<item barcode='111'><name>Foo</name><quantity>100</quantity></item>",
    new RequestCallback() { ... }
);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜