Ajax ------ Json, jqueryajaxjson

Source: Internet
Author: User

Ajax ------ Json, jqueryajaxjson

Background code:

 

String result = "";List<DeviceSensor> devices = deviceSensorService.findAll();JSONArray array = new JSONArray();for (DeviceSensor deviceSensor : devices) {try {String apMac = deviceSensor.getApMac();if(apMac == null) continue;DeviceAp deviceAp = deviceApService.findByAddress(apMac);Map<String,Object> map = new HashMap<String, Object>();map.put("apmac", apMac);map.put("apx", deviceAp.getX());map.put("apy", deviceAp.getY());map.put("sensormac", deviceSensor.getMac());map.put("sensorx", deviceSensor.getX());map.put("sensory", deviceSensor.getY());array.add(map);} catch (Exception e) {}}result = array.toString();try {response.setContentType("application/json;charset-utf-8");response.setContentLength(result.length());response.setCharacterEncoding("utf-8");response.getWriter().write(result);response.getWriter().flush();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}

 

  

 

Return Json Data Format

 

Js Code:

Refresh (); window. markers = []; window. markerList = new Array (); window. label = new Array (); function refresh () {$. ajax ({type: "GET", dataType: "json", url: "$ {ctx}/link/ajax", success: function (data) {var arr = eval (data); for (var I = 0; I <arr. length; I ++) {if (arr [I]. apy = null | arr [I]. retrial = null) continue; var station = new BMap. point (arr [I]. retrial, arr [I]. apy); // create the markerList [I] = new BMap. marker (new BMap. point (arr [I]. sensorx, arr [I]. sensory); // creates a map annotation. addOverlay (markerList [I]); markerList [I]. setTitle (arr [I]. sensormac); markers. push (markerList [I]); var points = [station, new BMap. point (arr [I]. sensorx, arr [I]. sensory)]; var curve = new BMapLib. curveLine (points, {strokeColor: "blue", strokeWeight: 3, strokeOpacity: 0.5}); // create an arc object map. addOverlay (curve); // Add it to the map. enableEditing (); // enable the editing function/* alert ("apmac:" + arr [I]. apmac + "\ n" + "retrial:" + arr [I]. retrial + "\ n" + "apy:" + arr [I]. apy + "\ n" + "sensormac:" + arr [I]. sensormac + "\ n" + "sensorx:" + arr [I]. sensorx + "\ n" + "sensory:" + arr [I]. sensory + "\ n") */} cluster () ;}, error: function (XMLHttpRequest, textStatus, errorThrown) {alert (errorThrown );}});}

  

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.