2016-07-06 52 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

相關問題