java web项目实例源码
求一套完整的JAVA WEB项目的网络购物网站源代码
关于java web的一段代码:jQuery ajax - getJSON() 方法:
在 jQuery 1.2 中,您可以通过使用 JSONP 形式的回调函数来加载其他网域的 JSON 数据,如 "myurl?callback=?"jQuery 将自动替换 ? 为正确的函数名,以执行回调函数 注意:此行以后的代码将在这个回调函数执行前执行
通过get请求得到json数据:
·url用于提供json数据的地址页
·data(Optional)用于传送到服务器的键值对
·callback(Optional)回调函数,json数据请求成功后的处理函数
望采纳! (随机推荐阅读本站500篇优秀文章点击前往:500篇优秀随机文章)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418 | /** * @description: * @author chenshiqiang E-mail:csqwyyx@163.com * @date 2014年9月7日 下午2:51:50 * @version 1.0 */ package com.example.baidumap; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; import android.app.Activity; import android.os.Bundle; import android.support.v4.view.PagerAdapter; import android.support.v4.view.PagerTabStrip; import android.support.v4.view.ViewPager; import android.text.Editable; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ExpandableListView; import android.widget.ListView; import com.baidu.mapapi.map.offline.MKOLSearchRecord; import com.baidu.mapapi.map.offline.MKOLUpdateElement; import com.baidu.mapapi.map.offline.MKOfflineMap; import com.baidu.mapapi.map.offline.MKOfflineMapListener; import com.example.baidumap.adapters.OfflineExpandableListAdapter; import com.example.baidumap.adapters.OfflineMapAdapter; import com.example.baidumap.adapters.OfflineMapManagerAdapter; import com.example.baidumap.interfaces.OnOfflineItemStatusChangeListener; import com.example.baidumap.models.OfflineMapItem; import com.example.baidumap.utils.CsqBackgroundTask; import com.example.baidumap.utils.ToastUtil; import com.example.system.R; public class BaiduOfflineMapActivity extends Activity implements MKOfflineMapListener, OnOfflineItemStatusChangeListener { // ------------------------ Constants ------------------------ // ------------------------- Fields -------------------------- private ViewPager viewpager; private PagerTabStrip pagertab; private MySearchView svDown; private ListView lvDown; private MySearchView svAll; private ExpandableListView lvWholeCountry; private ListView lvSearchResult; private List<View> views = new ArrayList<View>( 2 ); private List<String> titles = new ArrayList<String>( 2 ); private MKOfflineMap mOffline = null ; private OfflineMapManagerAdapter downAdapter; private OfflineMapAdapter allSearchAdapter; private OfflineExpandableListAdapter allCountryAdapter; private List<OfflineMapItem> itemsDown; // 下载或下载中城市 private List<OfflineMapItem> itemsAll; // 所有城市,与热门城市及下载管理对象相同 private List<OfflineMapItem> itemsProvince; private List<List<OfflineMapItem>> itemsProvinceCity; // ----------------------- Constructors ---------------------- // -------- Methods for/from SuperClass/Interfaces ----------- @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_offline_map); // final String packname = this.getPackageName(); // PackageInfo packageInfo; // try // { // packageInfo = this.getPackageManager().getPackageInfo(packname, PackageManager.GET_SIGNATURES); // // // if (code == -00) // { // 初始化离线地图管理 mOffline = new MKOfflineMap(); mOffline.init( this ); initViews(); viewpager.setCurrentItem( 1 ); // } // } // catch (NameNotFoundException e) // { // e.printStackTrace(); // } } private boolean isResumed = false ; @Override protected void onResume() { super .onResume(); if (!isResumed) { isResumed = true ; loadData(); } } @Override protected void onDestroy() { super .onDestroy(); mOffline.destroy(); } /** * * @author chenshiqiang E-mail:csqwyyx@163.com * @param type * 事件类型: MKOfflineMap.TYPE_NEW_OFFLINE, MKOfflineMap.TYPE_DOWNLOAD_UPDATE, MKOfflineMap.TYPE_VER_UPDATE. * @param state * 事件状态: 当type为TYPE_NEW_OFFLINE时,表示新安装的离线地图数目. 当type为TYPE_DOWNLOAD_UPDATE时,表示更新的城市ID. */ @Override public void onGetOfflineMapState( int type, int state) { switch (type) { case MKOfflineMap.TYPE_DOWNLOAD_UPDATE: MKOLUpdateElement update = mOffline.getUpdateInfo(state); if (setElement(update, true ) != null ) { if (itemsDown != null && itemsDown.size() > 1 ) { Collections.sort(itemsDown); } refreshDownList(); } else { downAdapter.notifyDataSetChanged(); } allSearchAdapter.notifyDataSetChanged(); allCountryAdapter.notifyDataSetChanged(); break ; case MKOfflineMap.TYPE_NEW_OFFLINE: // 有新离线地图安装 Log.d( "OfflineDemo" , String.format( "add offlinemap num:%d" , state)); break ; case MKOfflineMap.TYPE_VER_UPDATE: // 版本更新提示 break ; } } /** * 百度下载状态改变(暂停--恢复)居然不回调,所以改变状态时自己得增加接口监听状态改变刷新界面 * * @author chenshiqiang E-mail:csqwyyx@163.com * @param item * 有状态改变的item * @param removed * item是否被删除 */ @Override public void statusChanged(OfflineMapItem item, boolean removed) { if (removed) { for ( int i = itemsDown.size() - 1 ; i >= 0 ; i--) { OfflineMapItem temp = itemsDown.get(i); if (temp.getCityId() == item.getCityId()) { itemsDown.remove(i); } } refreshDownList(); } else { loadData(); downAdapter.notifyDataSetChanged(); } allSearchAdapter.notifyDataSetChanged(); allCountryAdapter.notifyDataSetChanged(); } // --------------------- Methods public ---------------------- public void toDownloadPage() { viewpager.setCurrentItem( 0 ); } // --------------------- Methods private --------------------- private void initViews() { // TODO viewpager = (ViewPager) findViewById(R.id.viewpager); pagertab = (PagerTabStrip) findViewById(R.id.pagertab); LayoutInflater inf = LayoutInflater.from( this ); View v1 = inf.inflate(R.layout.view_offline_download, null , false ); svDown = (MySearchView) v1.findViewById(R.id.svDown); lvDown = (ListView) v1.findViewById(R.id.lvDown); views.add(v1); View v2 = inf.inflate(R.layout.view_offline_countrys, null , false ); svAll = (MySearchView) v2.findViewById(R.id.svAll); lvWholeCountry = (ExpandableListView) v2.findViewById(R.id.lvWholeCountry); lvSearchResult = (ListView) v2.findViewById(R.id.lvSearchResult); views.add(v2); titles.add( "下载管理" ); titles.add( "城市列表" ); pagertab.setTabIndicatorColor( 0xff00cccc ); pagertab.setDrawFullUnderline( false ); pagertab.setBackgroundColor( 0xFF38B0DE ); pagertab.setTextSpacing( 50 ); viewpager.setOffscreenPageLimit( 2 ); viewpager.setAdapter( new MyPagerAdapter()); svDown.setSearchListener( new MySearchView.SearchListener() { @Override public void afterTextChanged(Editable text) { refreshDownList(); } @Override public void search(String text) { } }); svAll.setSearchListener( new MySearchView.SearchListener() { @Override public void afterTextChanged(Editable text) { refreshAllSearchList(); } @Override public void search(String text) { } }); downAdapter = new OfflineMapManagerAdapter( this , mOffline, this ); lvDown.setAdapter(downAdapter); allSearchAdapter = new OfflineMapAdapter( this , mOffline, this ); lvSearchResult.setAdapter(allSearchAdapter); allCountryAdapter = new OfflineExpandableListAdapter( this , mOffline, this ); lvWholeCountry.setAdapter(allCountryAdapter); lvWholeCountry.setGroupIndicator( null ); } /** * 刷新下载列表, 根据搜索关键字及itemsDown 下载管理数量变动时调用 */ private void refreshDownList() { String key = svDown.getInputText(); if (key == null || key.length() < 1 ) { downAdapter.setDatas(itemsDown); } else { List<OfflineMapItem> filterList = new ArrayList<OfflineMapItem>(); if (itemsDown != null && !itemsDown.isEmpty()) { for (OfflineMapItem i : itemsDown) { if (i.getCityName().contains(key)) { filterList.add(i); } } } downAdapter.setDatas(filterList); } } /** * 刷新所有城市搜索结果 */ private void refreshAllSearchList() { String key = svAll.getInputText(); if (key == null || key.length() < 1 ) { lvSearchResult.setVisibility(View.GONE); lvWholeCountry.setVisibility(View.VISIBLE); allSearchAdapter.setDatas( null ); } else { lvSearchResult.setVisibility(View.VISIBLE); lvWholeCountry.setVisibility(View.GONE); List<OfflineMapItem> filterList = new ArrayList<OfflineMapItem>(); if (itemsAll != null && !itemsAll.isEmpty()) { for (OfflineMapItem i : itemsAll) { if (i.getCityName().contains(key)) { filterList.add(i); } } } allSearchAdapter.setDatas(filterList); } } private void loadData() { new CsqBackgroundTask<Void>( this ) { @Override protected Void onRun() { // TODO Auto-generated method stub // 导入离线地图包 // 将从官网下载的离线包解压,把vmp文件夹拷入SD卡根目录下的BaiduMapSdk文件夹内 // 把网站上下载的文件解压,将BaiduMapvmpl里面的.dat_svc文件,拷贝到手机BaiduMapSDK/vmp/h目录下 int num = mOffline.importOfflineData(); if (num > 0 ) { ToastUtil.showToastInfo(BaiduOfflineMapActivity. this , "成功导入" + num + "个离线包" , false ); } List<MKOLSearchRecord> all = null ; try { all = mOffline.getOfflineCityList(); } catch (Exception e) { e.printStackTrace(); } if (all == null || all.isEmpty()) { ToastUtil.showToastInfo(BaiduOfflineMapActivity. this , "未获取到离线地图城市数据,可能有其他应用正在使用百度离线地图功能!" , false ); return null ; } List<MKOLSearchRecord> hotCity = mOffline.getHotCityList(); HashSet<Integer> hotCityIds = new HashSet<Integer>(); if (!hotCity.isEmpty()) { for (MKOLSearchRecord r : hotCity) { hotCityIds.add(r.cityID); } } itemsAll = new ArrayList<OfflineMapItem>(); itemsDown = new ArrayList<OfflineMapItem>(); itemsProvince = new ArrayList<OfflineMapItem>(); itemsProvinceCity = new ArrayList<List<OfflineMapItem>>(); // cityType 0:全国;1:省份;2:城市,如果是省份,可以通过childCities得到子城市列表 // 全国概略图直辖市港澳 子城市列表 ArrayList<MKOLSearchRecord> childMunicipalities = new ArrayList<MKOLSearchRecord>(); proHot.cityName = "热门城市" ; proHot.childCities = cs; List<MKOLUpdateElement> updates = mOffline.getAllUpdateInfo(); if (updates != null && updates.size() > 0 ) { } @Override protected void onResult(Void result) { // TODO Auto-generated method stub refreshDownList(); refreshAllSearchList(); allCountryAdapter.setDatas(itemsProvince, itemsProvinceCity); } }.execute(); } |
在 jQuery 1.2 中,您可以通过使用 JSONP 形式的回调函数来加载其他网域的 JSON 数据,如 "myurl?callback=?"jQuery 将自动替换 ? 为正确的函数名,以执行回调函数 注意:此行以后的代码将在这个回调函数执行前执行
通过get请求得到json数据:
·url用于提供json数据的地址页
·data(Optional)用于传送到服务器的键值对
·callback(Optional)回调函数,json数据请求成功后的处理函数
望采纳! (随机推荐阅读本站500篇优秀文章点击前往:500篇优秀随机文章)
来源:本文由易搜IT博客原创撰写,欢迎分享本文,转载请保留出处和链接!