2016-06-13 6 views
0

ポストjsonデータで送信したい。アリアテンプレート - 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 
     } 
    }); 
}, 

私はと思いますリクエストがサーバーに到着しないようにするために、リクエストはアリアテンプレートから出てこない。私が得る応答は:

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;

要求にこれらの2つの行を追加するには、要求がサーバに到着した働かせた:

新しいアプローチ、パートナーがいることを教えてくれました。しかし、今私たちはこのサービスの応答を得ています

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

サーバーの応答はJSON構造です。私たちは適切な対応を得るために取り組んでいます。

+0

クロスドメインエラーのように見えます。 CORS用にIISを設定しましたか? –

+0

はいはい...私はパートナー(@ヤニック)によって与えられた新しい良いアプローチをここに投稿します。それはほとんど終わりましたが、私たちはまだレスポンスでこの問題を抱えています... – 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;

リクエストにこれらの2行を追加すると機能しました。

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

関連する問題