url=url+calsign+"&dept="+deptString+"&dest="+destString+"&deptDate="+flightdate+"&deptTime="+flighttime+"&flightTime="+flyingtime+"&pilot="+'Mani'+":"+'Gnana'+"+&copilot="+'Mani'+":"+'Gnana'+"&crew="+'Mani'+":"+'Gnana'+"&userName="+user;
$.get(url, function(data) {
$.each(data, function(i, item) {
var div = '<div class="row" id="flightsummary"><div class="col-md-6"><div class="summary"><p> Transportation Start Time ='+data[i]['TRANSPORT_START_TIME'];+'</p><p> Reporting Start Time ='+data[i]['REPORTING_START_TIME'];+'</p><p> Chocks Off Time ='+data[i]['CHOCKS_OFF_TIME'];+'</p><p> Chocks On Time ='+data[i]['CHOCKS_ON_TIME'];+'</p><p>+Duty End Time ='+data[i]['DUTY_END_TIME'];+'</p><p> Flight Time ='+ data[i]['FLIGHT_TIME'];+'</p><p> Flight Duty Period ='+data[i]['FLIGHT_DUTY_PERIOD'];+'</p></p></div></div><div class="col-md-6"><div class="summary summary-right"><p> Rest Period Start Time ='+data[i]['REST_PERIOD_START_TIME'];+'</p><p> Minimum Rest Hours ='+data[i]['MINIMUM_REST_HOURS'];+'</p><p> Next Transportation Start Time <span class="calendar"></span> ='+data[i]['NEXT_TRNS_START_TIME'];+'</p><p> Next Reporting Time <span class="calendar"></span> ='+data[i]['NEXT_REPORTING_TIME'];+'</p><p> Next Earliest Take Off <span class="calendar"></span> ='+data[i]['NEXT_EARLIEST_TAKE_OFF'];+'</p><p> Last Landing Time <span class="calendar"></span> ='+data[i]['LAST_LANDING_TIME'];+'</p></div></div></div>;';
$('#summary').append(div);
});
}).fail(function() {
console.log("failed to load");
}).done(function() {
console.log("success to load");
});
我试图将一个div附加到具有数据响应的html,能够通过控制台日志单独查看数据但是无法将所有数据附加到html,只有第一个数据打印为(
Transportation Start Time ='+data[i]['TRANSPORT_START_TIME'];+
答案 0 :(得分:0)
问题在于div元素的构造,你使用单引号作为主字符串,双引号作为属性值。报价不匹配正在发生,因此它没有考虑为有效的HTML。
请构建如下的html:
String form_id = "237";
String module_list = "DSCHR";
String username = "Test Test";
String PUID = discharge_id + "|" + facility_id + "|"
+ "739739282898322" + "|" + "909283676222992";
String USER = "0" + "|" + security_id + "|" + "DSCHR" + "|" + "0";
String url = "callMe&PUID=" + PUID + "&USER=" + USER
+ "&username=" + username + "&form_id=" + form_id
+ "&module_list=" + module_list;
try {
CloseableHttpClient client = HttpClients.createDefault();
HttpPost post = new HttpPost(
"http://my-xyz-url/document?action="
+ URLEncoder.encode(url));
List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
urlParameters.add(new BasicNameValuePair("PUID", PUID));
urlParameters.add(new BasicNameValuePair("USER", USER));
urlParameters.add(new BasicNameValuePair("username", username));
urlParameters.add(new BasicNameValuePair("form_id", form_id));
urlParameters.add(new BasicNameValuePair("module_list", module_list));
post.setEntity(new UrlEncodedFormEntity(urlParameters, "UTF-8"));
CloseableHttpResponse response = client.execute(post);
BufferedReader rd = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
}