2016-10-20 5 views
0

폴리머 앱을 개발 중이며 RestApi를 호출하려고합니다. 이있는 요청 본문 내가 내가 PARAMS 이러한 매개 변수를 지정하는 방법의 적절한 아이디어를 얻고 있지 않다RestApi는 폴리머의 iron-ajax를 호출합니다.

{ 
    "languageId": Presently English is the only supported language. Always 1, 
    "productCode":"Medicus", 
    "timeZoneName":"Time zone name of device. For e.g. Asia/Calcutta", 
    "timeZoneOffset": Time zone offset from UTC in milliseconds. For e.g. IST = 19800000, 
    "user":{ 
    "firstName":"First name of the user", 
    "lastName":"Last name of the user", 
    "middleName":"Middle name of the user", 
    "password":"Password provided by the user", 
    "userTypeId":2 = Doctor, 3 = User, 
    "fields":[ 
     { 
      "Id":1, 
      "values":["Mobile number provided by the user”] 
     } 
    ] 
    } 
} 

얼마나 = '{}'철 - 아약스 요소.

+0

, 당신의 JSON이 유효 http://jsonlint.com을 확인하고이 코드를 붙여 넣습니다.. 당신이 잘못 무엇을 볼 수 –

답변

0

템플릿이 같은 넣어 뭔가 (당신이 당신의 문제 body 말했다 이후, 당신의 휴식 API에 POST를 가정입니다. 그 GET params=

<iron-ajax 
     id="fetchday" 
     url="/api/fetchday" 
     handle-as="json" 
     content-type="application/json" 
     method="POST" 
     body="[[params]]" 
     last-response="{{results}}" 
     on-response="_gotData" 
     on-error="_error"></iron-ajax> 

과 그리고 당신의 폴리머 요소 속성

을에 body=을 교체하는 경우 우선 들어
Polymer({ 
    is: 'my-element' 
    properties: { 
    params: { 
    type: Object 
    } 
    }, 
    _someFunction: function() { 
    this.params = //ASSIGN YOUR JSON OBJECT TO PARAMS HERE 
    this.$.fetchday.generateRequest(); 
    }, 
    _gotData: function(e) { 
    //response data is in both this.results and e.detail.response 
}, 
_error: function() { 
} 
}); 
+0

난 솔루션 – aries12

+0

을 시도했지만 지금은 50을 받고 있습니다 2 프록시 오류 params에 JSON.stringify를 수행 한 다음 본문으로 전송해야합니까? 아니면 내용 유형을 고려하여 자체적으로 수행합니까? – aries12

+0

위 예제에서 this.params에 Javascript 객체를 제공합니다. 나는 그것의'handle-as = "json"을 철제 아약스에게 몸 안에 인코딩하는 법을 알려준다. – akc42