2016-06-13 46 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