Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 29th, 2012  |  syntax: None  |  size: 1.50 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. javascript function not returning correct value
  2. function PostcodeAnywhere_Interactive_FindByPostcode_v1_00(Key, Postcode, UserName) {
  3.  
  4.     var retval;
  5.  
  6.     $.getJSON("https://services.postcodeanywhere.co.uk/PostcodeAnywhere/Interactive/FindByPostcode/v1.00/json3.ws?",
  7.     {
  8.         Key: Key,
  9.         Postcode: Postcode,
  10.         UserName: UserName
  11.     },
  12.     function (response) {
  13.         // Test for an error
  14.         if (response.Items.length == 1 && typeof(response.Items[0].Error) != "undefined") {
  15.             // Show the error message
  16.             retval = false;
  17.         } else {
  18.             // Check if there were any items found
  19.             if (response.Items.length == 0){
  20.                 retval = false;
  21.             } else {
  22.                 retval = true;
  23.             }
  24.         }
  25.     });
  26.  
  27. return retval;
  28.  
  29. }
  30.        
  31. $.getJSON("https://services.postcodeanywhere.co.uk/PostcodeAnywhere/Interactive/FindByPostcode/v1.00/json3.ws?",
  32.     {
  33.         Key: Key,
  34.         Postcode: Postcode,
  35.         UserName: UserName
  36.     },
  37.     function (response) {
  38.         // Test for an error
  39.         if (response.Items.length == 1 && typeof(response.Items[0].Error) != "undefined") {
  40.             // Show the error message
  41.             retval = false;
  42.         } else {
  43.             // Check if there were any items found
  44.             if (response.Items.length == 0){
  45.                 retval = false;
  46.             } else {
  47.                 retval = true;
  48.             }
  49.             //use retval
  50.             do_something_with_retval(retval);
  51.         }
  52.     });