2013-07-29 52 views
0

我通過適配器獲取JSON響應。如何將其填充到下拉列表中。我嘗試將php代碼插入到我的HTML代碼中。但它是打印itselp的代碼。從適配器填充JSON響應到下拉菜單

HTML Code: 



<!DOCTYPE HTML> 
    <html> 
     <head> 
       <meta charset="UTF-8"> 
       <title>TestApp</title> 
       <meta name="viewport" content="width=device-width, initial-scale=1.0, 
    maximum-scale=1.0, minimum-scale=1.0, user-scalable=0"> 
       <link rel="shortcut icon" href="images/favicon.png"> 
       <link rel="apple-touch-icon" href="images/apple-touch-icon.png"> 
       <link rel="stylesheet" href="css/TestApp.css"> 
       <script>window.$ = window.jQuery = WLJQ;</script> 



     </head> 
     <body id="content" style="display: none;"> 
       <!--application UI goes here--> 
       SOWRUN APP</br> 



    <p> employeenumber: <input type="text" id="employeenumber"/></br> 


    <p><br>employeename:  <input type="text" id="employeename"/></br></p> 
    <p><br>employeeemail:  <input type="text" id="employeeemail"/></br></p> 
    <p><br>employeeadID:  <input type="text" id="employeeadID"/></br></p> 
    <p><br>businessUnit:  <input type="text" id="businessUnit"/></br></p> 
    <select name="country" id="country"> 

    <option>Select Country</option> 
    <option>INDIA</option> 
    <option>USA</option> 
    </select> 



       <p><br>city:    <input type="text" id="city"/>  </br></p> 
      <p><br>location:   <input type="text"  id="location"/> 
       <p><br>bloodGroup:   <input type="text" id="bloodGroup"/> 
       <p><br>gender:    <input type="text" id="gender"/></br></p> 
       <p><br>tShirt:     <input type="text" id="tShirt"/> 


    <input type="button" onclick="submitName()" value="Submit"/></br> 



       <script src="js/initOptions.js"></script> 
       <script src="js/TestApp.js"></script> 
       <script src="js/messages.js"></script> 
     </body> 
    </html> 

我想有填充入我從適配器獲得「國家」下拉列表中的以下JSON響應。

JSON響應:

{ 
"array": [ 
     { 
     "con_name": "India" 
     }, 
     { 
     "con_name": "Portugal" 
     }, 
     { 
     "con_name": "Spain" 
     }, 
     { 
     "con_name": "UAE" 
     }, 
     { 
     "con_name": "USA" 
     }, 
     { 
     "con_name": "Mexico" 
     }, 
     { 
     "con_name": "Australia" 
     }, 
     { 
     "con_name": "Romania" 
     }, 
     { 
     "con_name": "Phillipines" 
     }, 
     { 
     "con_name": "Netherlands" 
     }, 
     { 
     "con_name": "UK" 
     }, 
     { 
     "con_name": "Singapore" 
     }, 
     { 
     "con_name": "Switzerland" 
     }, 
     { 
     "con_name": "Hungary" 
     }, 
     { 
     "con_name": "USAWest" 
     }, 
     { 
     "con_name": "USA South" 
     }, 
     { 
     "con_name": "Mexico" 
     }, 
     { 
     "con_name": "Brazil" 
     }, 
     { 
     "con_name": "China" 
     }, 
     { 
     "con_name": "NewZealand" 
     }, 
     { 
     "con_name": "Poland" 
     }, 
     { 
     "con_name": "Japan" 
     }, 
     { 
     "con_name": "Germany" 
     }, 
     { 
     "con_name": "Canada" 
     }, 
     { 
     "con_name": "France" 
     }, 
     { 
     "reg_AD_ID": "111111" 
     } 
    ], 
    "isSuccessful": true, 
    "responseHeaders": { 
     "Connection": "Keep-Alive", 
     "Content-Length": "594", 
     "Content-Type": "text\/html", 
     "Date": "Mon, 29 Jul 2013 07:01:37 GMT", 
     "Keep-Alive": "timeout=5, max=100", 
     "Server": "Apache\/2.2.21 (Win32) PHP\/5.3.8", 
     "X-Powered-By": "PHP\/5.3.8" 
    }, 
    "responseTime": 85, 
    "statusCode": 200, 
    "statusReason": "OK", 
    "totalTime": 85 
} 
+0

請建議我如何去了解它。 – Sadanand

回答

1

您創建一個SQL adapter,右:從工作燈服務器 '的getCountries':程序 調用結果?

在JS你有一個適配器的過程,如:

function procedureXX(param){ 
     var invocationData={ 
       adapter : 'NameAdapter', 
       procedure: 'procedureXMLName', 
       parameters:[param] 
     }; 

     WL.Client.invokeProcedure(invocationData, 
       { 
      onSuccess: function(result){ 
       onSuccessFunc(result); 
      }, 
      onFailure: function(){ 
       WL.Logger.debug("failed"); 

      } 

      }  
    ); 
} 
在功能

onSuccessFunc您設置的下拉菜單與innerHTML的

function onSuccessSelectAllCodiciClienti(result){ 

     if (result.invocationResult.resultSet.length>0) { 
      var cod=result.invocationResult.resultSet; 
      var select=..... 
      for (var i=0;i<cod.length;i++){ 
       select+=" ... cod["+i+"].con_name} ... "; 

      } 


     } 
     var vText = document.getElementById("drop_down_menu_HTML_id"); 
    vText.innerHTML = select; 
    } 
+0

功能的getCountries(){ \t \t 變種輸入= { \t方法: '得到', \t returnedContentType: 'JSON', \t路徑: 「IOS/country.php」 \t \t \t \t }; \t \t return WL.Server.invokeHttp(input); } – Sadanand

+0

我在我的HTTP適配器中有這樣的代碼。 – Sadanand

+0

感謝您的幫助。我正在嘗試。 – Sadanand