Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you have access to jQuery I would use it's ajax function to call a wcf web service that returns the relevant address information in a JSON format. Otherwise, you could create your own XHR request and parse the response.</p> <pre><code>$('#zipCodeClient').blur(function() { var zipCode = $(this).val(); if(zipCode.length &gt;= 5 &amp;&amp; zipCode.length &lt;= 10) { $.ajax({ type: 'GET', data: { ZipCode: zipCode }, url: 'something/ZipCodeToAddressService', dataType: 'json', contentType: 'application/json; charset=utf-8', success: function(data) { var responseObject = jQuery.parseJSON(data); $('#cityTextBox').val(responseObject.City); $('#stateTextBox').val(responseObject.State); } }); } else { // zip code not valid } }); </code></pre> <p>In WCF:</p> <pre><code>[ServiceContract()] public interface IAddressServices { [OperationContract()] [WebGet(ResponseFormat = WebMessageFormat.Json)] string ZipCodeToAddressService(string ZipCode); } [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)] public class AddressServices : IAddressServices { public string ZipCodeToAddressService(string ZipCode) { using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["DB"].ConnectionString)) { using (SqlCommand sqlCmd = new SqlCommand("ZipCodeToAddressStoredProc", sqlConnection)) { sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.Parameters.Add("@Zip", SqlDbType.NVarChar).Value = ZipCode; sqlConnection.Open(); SqlDataReader sDR = sqlCmd.ExecuteReader(CommandBehavior.CloseConnection); DataTable tbl = new DataTable(); tbl.Load(sDR); sDR.Close(); var citystateData = from DataRow Row in tbl.AsEnumerable() select new { City = Row.Field&lt;string&gt;("City"), State = Row.Field&lt;string&gt;("State") }; JavaScriptSerializer js = new JavaScriptSerializer(); StringBuilder sb = new StringBuilder(); js.Serialize(cityStateData, sb); string rtrnCityStateData = sb.ToString(); return rtrnCityStateData; } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload