Skip to content

Instantly share code, notes, and snippets.

@wvpv
Created June 15, 2019 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wvpv/2734a4b739d4091894057cc359f86fdd to your computer and use it in GitHub Desktop.
Save wvpv/2734a4b739d4091894057cc359f86fdd to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Cities</title>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
</head>
<body>
<h4>Cities</h4>
<label>State:</label> <input type="text" name="state" id="state" size="2">
<p><button type="button" class="btn">Load Cities</button></p>
<p class="cities"></p>
<script type="text/javascript">
$('.btn').click(function() {
$('.cities').text('Loading...');
var state = $('#state').val();
$.ajax({
type:"GET",
url:"https://pub.s7.exacttarget.com/kmsrachtfig?state=" + state,
dataType: "json",
contentType: "application/json",
cache: !1,
timeout: 1e4,
success: function(data) {
console.log(data)
var $el0 = $('.cities');
$el0.empty();
$el0.append($("<select></select>").attr("class","cityList"));
var $el = $('.cityList');
$el.append($("<option></option>").attr("value", '').text('Select City'));
$.each(data.results, function(value, key) {
$el.append($("<option></option>").attr("value", key.City).text(key.City + ", " + key.State));
});
}
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment