2016-09-01 8 views
-4

連結URLのコンソールログを取得しようとしていますが、新しい変数を作成しようとしましたが、これをconsole.logに渡して成功しませんでした。http.postデータからconsole.logを取得する

私が投稿しようとしているURLのログを取得するにはどうすればよいですか?

 $scope.sendPaymentConfirmation = function (ordernumber) { 
     //function sendPaymentConfirmation(ordernumber) { 
      $http({ 
       url: ('http://example.com/api/' + ordernumber), //'http://samedomain.com/GetPersons', 
       var posturl = url; 
       console.log(posturl); 
       method: "POST", 
       //data: postData, 
       headers: {'Content-Type': 'application/x-www-form-urlencoded'} 
      }) 
      .then(function(response) { 
        // success : Thankyou, payment confirmation has been sent to the API server 
        window.alert('SUCCESS - Payment confirmation has been sent to the API server'); 
       }, 
       function(response) { // optional 
        // failed : ERROR There has been an error sending payment confirmation to the API server 
        window.alert('ERROR - There has been an error sending payment confirmation to the API server'); 
       } 
      ); 
     } 

答えて

0

オブジェクトリテラルはステートメントとセミコロンを含むことはできません。 @Quentinが提案する標準的な方法をしたくない場合は、次のように(即座の関数呼び出し)これを行うことができます:

$http({ 
      url: (function(){ 
        var posturl = 'http://example.com/api/' + ordernumber; //'http://samedomain.com/GetPersons', 
        console.log(posturl); 
        return posturl; 
      })(), 
      method: "POST", 
      //data: postData, 
      headers: {'Content-Type': 'application/x-www-form-urlencoded'} 
     }) 
0

オブジェクトリテラル内に変数を作成することはできません。他の任意のJSのステートメントをそこに置くこともできません。

最初に変数を作成します。その後、それを使用してください。

関連する問題