2016-07-06 6 views
0

私は自分のサイトにPostcode Anywhereを実装しようとしています。郵便番号フィールドに郵便番号を入力すると、その郵便番号とユーザに関連するアドレスが表示されます該当するアドレスを選択し、アドレスの詳細は、私のページに次のコードを使用しています入射アドレスfield.Iの残りの部分を移入します:私のサイトにPostcode Anywhereを実装しようとしています

function CapturePlus_Interactive_Find_v2_10Begin(Key, SearchTerm, LastId, SearchFor, Country, LanguagePreference, MaxSuggestions, MaxResults) { 
    var script = document.createElement("script"), 
     head = document.getElementsByTagName("head")[0], 
     url = "http://services.postcodeanywhere.co.uk/CapturePlus/Interactive/Find/v2.10/json3.ws?"; 

    // Build the query string 
    url += "&Key=" + encodeURIComponent(Key); 
    url += "&SearchTerm=" + encodeURIComponent(SearchTerm); 
    url += "&LastId=" + encodeURIComponent(LastId); 
    url += "&SearchFor=" + encodeURIComponent(SearchFor); 
    url += "&Country=" + encodeURIComponent(Country); 
    url += "&LanguagePreference=" + encodeURIComponent(LanguagePreference); 
    url += "&MaxSuggestions=" + encodeURIComponent(MaxSuggestions); 
    url += "&MaxResults=" + encodeURIComponent(MaxResults); 
    url += "&callback=CapturePlus_Interactive_Find_v2_10End"; 

    script.src = url; 

    // Make the request 
    script.onload = script.onreadystatechange = function() { 
     if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") { 
      script.onload = script.onreadystatechange = null; 
      if (head && script.parentNode) 
       head.removeChild(script); 
     } 
    } 

    head.insertBefore(script, head.firstChild); 
} 

function CapturePlus_Interactive_Find_v2_10End(response) { 
    // Test for an error 
    if (response.Items.length == 1 && typeof(response.Items[0].Error) != "undefined") { 
     // Show the error message 
     alert(response.Items[0].Description); 
    } 
    else { 
     // Check if there were any items found 
     if (response.Items.length == 0) 
      alert("Sorry, there were no results"); 
     else { 
      // PUT YOUR CODE HERE 
      //FYI: The output is an array of key value pairs (e.g. response.Items[0].Id), the keys being: 
      //Id 
      //Text 
      //Highlight 
      //Cursor 
      //Description 
      //Next 
     } 
    } 
} 

を私は他の部分に書かれたことがあるかわかりません(私は値をマップするために実際のコードを置く必要があります)。誰もがこれで私を助けてくれますか?

+0

ページの後ろにコードを見て何を示して...ですから、http://services.postcodeanywhere.co.uk/からコードをコピーして、ここでいくつかの助けをしたいですあなたは終わった。 – lordkain

答えて

0

サイトを見ると、実際の例があります。

http://www.pcapredict.com/support/webservice/captureplus/interactive/find/2.1/

幸運

function TestCallBack(response){ 
var _strHtml=''; 
var _intColumn=0; 
var _intRow=0; 
var _strColumns= new Array('Id','Text','Highlight','Cursor','Description','Next'); 
var _strColumn=''; 
//Hide the waiting panel 
document.getElementById('btnTest').innerHTML = 'Start the test'; 
document.getElementById('btnTest').disabled = false; 
document.getElementById('pnlOutput').style.display='block'; 
//Test for an error 
if (response.length==1 && typeof(response[0].Error) != 'undefined'){ 
//Show the error message 
_strHtml = '<table cellpadding="0" cellspacing="0" class="doc-table" style="width: 100%;">'; 
_strHtml += '<thead><tr><th><span class="cboxtl"></span>Error</th><th>Description</th><th>Cause</th><th><span class="cboxtr"></span>Resolution</th></tr></thead>'; 
_strHtml += '<tr><td>' + response[0].Error + '</td><td>' + response[0].Description + '</td><td>' + response[0].Cause + '</td><td>' + response[0].Resolution + '</td></tr>'; 
_strHtml += '</table>'; 
//Update the DIV 
document.getElementById('pnlHeading').innerHTML = '<h2>Error</h2>'; 
document.getElementById('pnlError').innerHTML = _strHtml; 
document.getElementById('pnlError').style.display='block'; 
} 
else{ 
//Check if there were any items found 
if (response.length==0){ 
_strHtml = '<h2>Sorry, no matching items found</h2>'; 
} 
else{ 
//Add the headings to the table 
_strHtml += '<table cellpadding="0" cellspacing="0" class="doc-table" style="width: 100%; table-layout:auto;">'; 
_strHtml += '<thead><tr>'; 
for (_intColumn=0; _intColumn<_strColumns.length; _intColumn++) 
{ 
_strHtml += '<th>' + _strColumns[_intColumn] + '</th>'; 
} 
_strHtml += '</tr></thead>'; 
//Add the rows 
for (_intRow=0; _intRow<response.length; _intRow++){ 
_strHtml += '<tr>' 
if (response[_intRow].Id=='') { _strHtml += '<td>&nbsp;</td>' } else { _strHtml += '<td>' + response[_intRow].Id + '</td>' }; 
if (response[_intRow].Text=='') { _strHtml += '<td>&nbsp;</td>' } else { _strHtml += '<td>' + response[_intRow].Text + '</td>' }; 
if (response[_intRow].Highlight=='') { _strHtml += '<td>&nbsp;</td>' } else { _strHtml += '<td>' + response[_intRow].Highlight + '</td>' }; 
if (response[_intRow].Cursor=='') { _strHtml += '<td>&nbsp;</td>' } else { _strHtml += '<td>' + response[_intRow].Cursor + '</td>' }; 
if (response[_intRow].Description=='') { _strHtml += '<td>&nbsp;</td>' } else { _strHtml += '<td>' + response[_intRow].Description + '</td>' }; 
if (response[_intRow].Next=='') { _strHtml += '<td>&nbsp;</td>' } else { _strHtml += '<td>' + response[_intRow].Next + '</td>' }; 
_strHtml += '</tr>' 
} 
_strHtml += '</table>' 
} 
//Update the DIV 
document.getElementById('pnlHeading').innerHTML = '<h3>Results</h3>'; 
document.getElementById('pnlResults').innerHTML = _strHtml; 
document.getElementById('pnlResults').style.display='block'; 
document.getElementById('pnlError').style.display='none'; 
} 
} 
+0

あなたが与えたコードは値のテーブルを作成するだけです。私が欲しいのは、ポストコードフィールドに郵便番号を入力すると、関連する郵便番号のアドレスのドロップダウンが表示されるはずです。 – Princy

+0

何を試しましたか?あなたが試したもののバージョンと、助けたいところを表示してください。 – lordkain

+0

私は上に貼り付けたコードを使用するように頼まれました。しかし、私は郵便番号の入力を開始するときにドロップダウンを取得するように、コードをelse部分に追加する必要はありません – Princy

関連する問題