2016-06-13 45 views
0

我想通过post json数据发送。Aria模板 - 通过POST调用服务

我读的API文档(working in an asynchronous worldAPI doc IOAsyncRequestCfg),他们说,应该送这样的:

/* called when the template has been successfully rendered. */ 
    $viewReady : function(){ 
     console.log("$viewReady"); 

     var pnr = this.data.pnr; 
     var names = this.data.names; 
    var namesResults = []; 

    if (names.length > 0) 
    { 
     var monto = this.callAjaxService('https://localhost/Service1.asmx/SetNames?jsonp=false', names);//REST service 
    }    
    }, 

和呼叫的服务是:

callAjaxService : function (urlString, data) { 
    console.log("callAjaxService"); 
    console.log(urlString); 

    console.log(JSON.stringify(data)); 
    aria.core.IO.asyncRequest({ 
     url : urlString, 
     timeout : 10000, 
     async: true, 
     method: "POST", 
     data: JSON.stringify(data), 
     contentType: "application/json", 
     callback : { 
      fn : this.onSuccessId, 
      scope : this, 
      onerror : this.onError, 
      onerrorScope : this 
     } 
    }); 
}, 

我认为,该请求没有退出aria模板,请求永远不会到达服务器。因为我得到的回应是:

error:"error"
errorText:"Error #2048"
errorType:"securityError" reqId:249
responseText:"undefined"
status:0
statusText:"xdr:error"

我正在IIS上调试服务,它永远不会到达那里。我已经与其他客户端测试过该服务,并且它可以正常工作。

新方法,一个合伙人告诉我说:

When CORS is enabled, you can use a regular transport, based on XHR. In order to tell Aria Templates to do so, you can execute this code before any cross domain request:

aria.core.IO.updateTransports({ 'crossDomain': 'aria.core.transport.XHR' });

Also, due to the way CORS works to control what HTTP headers can be added to a request by the client, you should also execute this code:

aria.core.IO.useXHRHeader = false;

添加这两行请求使它工作的请求到达服务器。但是,现在我们正在获得此服务的响应

error:"13030"  
reqId: 255  
responseText:""  
responseXML:null  
status:13030 
url:"https://localhost/Service1.asmx/GetNames?jsonp=true&callback=pol 

服务器的响应是JSON结构。我们正在努力如何获得正确的回应。

+0

看起来像一个跨域错误。你配置了IIS的CORS? –

+0

是的是的...我有一个新的好方法(@Yannick)我会在这里发布。这几乎完成,但我们仍然有这个问题的答复... – paulofer85

回答

0

新的方法解决。一位合伙人告诉我:

When CORS is enabled, you can use a regular transport, based on XHR. In order to tell Aria Templates to do so, you can execute this code before any cross domain request:

aria.core.IO.updateTransports({ 'crossDomain': 'aria.core.transport.XHR' });

Also, due to the way CORS works to control what HTTP headers can be added to a request by the client, you should also execute this code:

aria.core.IO.useXHRHeader = false;

将这两行添加到请求使它工作。

0

也许这有助于

<!DOCTYPE html> 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="charset=utf-8" /> 
    <title>Hello World</title> 
    <script type="text/javascript" src="http://cdn.ariatemplates.com/atlatest.js"></script> 
</head> 
<body> 
    <div id="myContainer"></div> 
    <script type="text/javascript"> 
    aria.core.IO.asyncRequest({ 
     url : 'http://httpbin.org/post', 
     method : "post", 
     callback : { 
      fn : function (response, args) { 
       console.log('response:', response); 
      }, 
      scope : this 
     } 
    }); 
    </script> 
</body> 
</html> 
+0

@Facu_Tkaczyszyn谢谢,这是一个很好的方式来知道所有的日志:) – paulofer85