2012-11-21 228 views
0

我創建了一行代碼,用於從SOAP服務讀取數據。但我有一個小問題。我在這個任務中使用JSONP Lib,但沒有產生結果。我使用較少的代碼嘗試讀取數據庫查詢的輸出,結果是成功的。這兩種方法有區別嗎?我提出的PHP代碼的第一個到所述陣列轉移到JSON的形式:閱讀JSON格式

<?php 
error_reporting(0); 
header('content-type:application/json;charset=UTF-8'); 
date_default_timezone_set("Asia/Jakarta"); 
require_once('lib/nusoap.php'); 

$Param1 = "[email protected]"; 
$Param2 = "12345"; 

$client = new nusoap_client('http://vcare.telkomvision.net.id/services/VcareServices.php'); 
$ReadSOAP = $client->call('validateLogin', array('EMAIL' => $Param1, 'PASSWORD' => md5($Param2))); 

echo '{"items":['. json_encode($ReadSOAP) .']}'; 
?> 

和上述代碼中產生的數據是:

{ 
"items": [ 
    { 
     "NE": "42616324457", 
     "EMAIL": "[email protected]", 
     "TIPE": "POSTPAID", 
     "NAMA": "ALBERTHO MALAQUENA JORIS/NPK:120488047", 
     "TELP": "081310117966/087878837451", 
     "DN": "127225148174", 
     "STATUS_LOGIN": "1", 
     "DESC_LOGIN": "Valid" 
     } 
    ] 
} 

我使用下面到庫稍後處理在我的應用程序要讀取的輸出數據: JSONP Library

JSONP.get('MyURL.php', {Email:'MyEmail', Password:'MyPass'}, function(data){ 
    for (var i = 0; i < response.length; ++i) { 
      str = response[i].ne; 
      str2 = response[i].email; 
      str3 = response[i].tipe; 
      str4 = response[i].nama; 
      str5 = response[i].telp; 
      str6 = response[i].dn; 
      str7 = response[i].desc_login; 
    } 
}); 

但結果我得到的是:我的應用A n無法直接從SOAP上面讀取數據輸出。我很困惑爲什麼會這樣。我認爲JSON格式是正確的。

然後我試着直接從數據庫中讀取數據。這個數據庫是一個示例,我意外地用上面的SOAP讀取過程的輸出來創建相同的數據。

結果,我成功獲取數據。

我包括兩個鏈接,我用來做閱讀。

  1. 此鏈接是PHP文件,直接從服務器處理SOAP和輸出JSON: Failed to Reading

  2. 這是直接鏈接到數據庫與虛擬數據庫。 JSON輸出。我成功使用第二種方法: Success to Reading

請幫我解決我的問題了。我想直接從使用輸出JSON的SOAP表單的流程中讀取數據。正如我所說的失敗。

謝謝

+0

(i)您應該迭代'data.items'(II)JavaScript和JSON是區分大小寫的。 'foo.ne'和'foo.NE'不一樣。 –

+0

我改變了,等於 –

+0

等一下幫助.. :( –

回答

0

試試這個:

JSONP.get('MyURL.php', {Email:'MyEmail', Password:'MyPass'}, function(data){ 
    for (var i = 0; i < response.length; i++) 
    { 
     str = response[i].NE; 
     str2 = response[i].EMAIL; 
     str3 = response[i].TIPE; 
     str4 = response[i].NAMA; 
     str5 = response[i].TELP; 
     str6 = response[i].DN; 
     str7 = response[i].DESC_LOGIN; 
    } 
});