【Appcelerator(简单的邮政编码城市查找器)】登山则情满于山,观海则意溢于海。这篇文章主要讲述Appcelerator:简单的邮政编码城市查找器相关的知识,希望能为你提供帮助。
Appcelerator Titanium Mobile is a framework + IDE designed to help you build iPhone applications using only html and javascript. This example shows how to make a simple Ajax request
- < html>
- < head>
- < title> Find City By ZIP Code< /title>
- < script type=" text/javascript" src=https://www.songbingjia.com/android/" jquery-1.3.2.js" > < /script>
- < style type=" text/css" media=" screen" >
- #textField{ width:100px; height:30px }
- #search-btn{ width:100px; height:47px; color:#0000ff; }
- #response-txt{ width:300px; text-align:center; font-family:helvetica, impact, sans-serif; font-weight: bold; }
- .center { margin-right:auto; margin-left:auto; width:320px; }
- < /style>
- < script type=" text/javascript" charset=" utf-8" >
- var xhr;
- var xhrResponse;
- var alert;
- var xmlCity;
- var xmlState;
- var zipCode;
- var tf;
- var searchBtn;
- function initialize( e) {
- /****************************
- Create Ajax Request
- ****************************/
- xhr = Titanium.Network.createHTTPClient( ) ;
- xhrResponse = $( " #response-txt" ) ;
- /****************************
- Create TextField
- ****************************/
- tf= Titanium.UI.createTextField( {
- id:'textField',
- value:'90026',
- color:'#336699',
- backgroundColor:'#eeeeee',
- returnKeyType:Titanium.UI.RETURNKEY_DONE,
- enableReturnKey:true,
- keyboardType:Titanium.UI.KEYBOARD,
- autocorrect:false,
- hintText:'Enter ZIP',
- textAlign:'left',
- clearOnEdit:true,
- borderStyle:Titanium.UI.INPUT_BORDERSTYLE_BEZEL,
- clearButtonMode:Titanium.UI.INPUT_BUTTONMODE_NEVER,
- } ) ;
- $( tf) .bind( " change" , onTfChangeHandler ) ;
- function onTfChangeHandler( e) {
- tf.value = https://www.songbingjia.com/android/e.value;
- }
- /****************************
- Create Search Button
- ****************************/
- searchBtn = Titanium.UI.createButton( { id:'search-btn', title:'Search' } ) ;
- $( searchBtn) .bind( " click" , onSearchClickHandler ) ;
- function onSearchClickHandler( e) {
- constructAndSend( ) ;
- }
- /****************************
- Ajax onLoad Request
- ****************************/
- xhr.onload = function( )
- {
- Titanium.API.info( " xhr.onload: " ) ;
- var xml = this.responseXML;
- // xml now is a Javascript DOM object you can use
- var xmlDoc = xml.documentElement;
- try {
- // get a value of the first tag myelement found in XML doc
- xmlCity = xmlDoc.getElementsByTagName( " CITY" ) [ 0] .childNodes[ 0] .nodeValue.toString( ) ;
- xmlState = xmlDoc.getElementsByTagName( " STATE" ) [ 0] .childNodes[ 0] .nodeValue.toString( ) ;
- } catch( err) {
- $( xhrResponse) .html = " " ;
- constructAlert( " Zip Code Not Found. " ) ;
- }
- //xhrResponse.innerHTML = zipCode + " < br> is the ZIP Code for< br> " + xmlCity + " , " + xmlState;
- $( xhrResponse) .html( zipCode + " < br> is the ZIP Code for< br> " + xmlCity + " , " + xmlState ) ;
- } ;
- }
- function constructAndSend( ) {
- //Capture the Zip Code
- zipCode = $( tf) .val( ) ;
- Titanium.API.info( " constructAndSend: " + zipCode ) ;
- //Confirm that a proper Zip Code has been entered
- if ( zipCode != null & & zipCode.length == 5 ) {
- //Fire Off the Ajax Request
- xhr.open( " GET" ," http://www.webservicex.net/uszip.asmx/GetInfoByZIP?USZip=" + zipCode) ;
- xhr.send( null) ;
- } else {
- //Show any errors
- constructAlert( " A 5-digit ZIP Code must be entered." ) ;
- }
- }
- /****************************
- Create Alert Message
- ****************************/
- function constructAlert( message ) {
- var alert = Titanium.UI.createAlertDialog( ) ;
- alert.setTitle( " Error" ) ;
- alert.setMessage( message ) ;
- alert.show( ) ;
- return;
- }
- < /script>
- < script type=" text/javascript" charset=" utf-8" >
- $( document) .ready( function( ) {
- initialize( ) ;
- } ) ;
- < /script>
- < body style=" background-color:#999999" >
- < div id=" textField" class=" center" > < /div>
- < br/>
- < div id=" search-btn" class=" center" > < /div>
- < br/> < br/>
- < div id=" response-txt" class=" center" > < /div>
- < /body>
- < /html>
推荐阅读
- Android警报对话框
- Kickapps(确定用户是否登录到外部页面)
- [jQuery]Appel脚本chez google API
- 在Android应用程序中集成Adobe Photoshop Mobile
- KickApps-更改表单验证以使用JQuery。修复IE的问题
- 清理旧的googleappengine会话
- KickApps-告诉用户是否已登录
- 从Android应用程序启动电话
- Android的OpenGL教程(构建Mandelbrot集生成器)