 |
jQuery + Ajax งงโค้ด..ปรับให้แสดงผลลัพธ์ได้เลยโดยไม่ต้องผ่าน Button(JS) |
|
 |
|
|
 |
 |
|
โค้ดเป็นโค้ดที่แจกฟรี แล้วก๊อปมาครับ
เกี่ยวกับกราฟแผนภูมิ +เรียกJs แต่ตรงนั้นผมเข้าใจว่าไม่ใช่ประเด็น
รบกวนคนเก่งๆช่วยหน่อยครับ ต้องตัด หรือเพิ่ม ดัดแปลงยังไง
ผมลองดูแล้วงมแล้ว ไม่ได้จริงๆครับ
ขอบคุณมากครับ
โค้ดครับ
Code (JavaScript)<div id="placeholder" style="width:300px;height:240px;padding:0px0px 0px 5px;margin-top:20px;"></div>
<img src="../images/icons/CalenderRight.gif" /><img src="../images/icons/CalenderRight.gif" /> <input name="bt" width="300" class="fetchSeries" type="button" value="แสดง 'สถิติ' Employees of us(PPM) chart" style="cursor:pointer;" title="Employee Chart"> -
<span><img src="../images/chart3d.png" border="0" /></span> -
<a href="../js/data-usa-gdp-growth.js"></a>
</p>
<script type="text/javascript">
$(function () {
var options = {
lines: { show: true },
points: { show: true },
xaxis: { tickDecimals: 0, tickSize: 1 }
};
var data = [];
var placeholder = $("#placeholder");
$.plot(placeholder, data, options);
// fetch one series, adding to what we got
var alreadyFetched = {};
$("input.fetchSeries").click(function () {
var button = $(this);
// find the URL in the link right next to us
var dataurl = button.siblings('a').attr('href');
// then fetch the data with jQuery
function onDataReceived(series) {
// extract the first coordinate pair so you can see that
// data is now an ordinary Javascript object
var firstcoordinate = '(' + series.data[0][0] + ', ' + series.data[0][1] + ')';
button.siblings('span').text('Fetched ' + series.label + ', lastcoordinate: ' + firstcoordinate + ' People');
// let's add it to our current data
if (!alreadyFetched[series.label]) {
alreadyFetched[series.label] = true;
data.push(series);
}
// and plot all we got
$.plot(placeholder, data, options);
}
$.ajax({
url: dataurl,
method: 'GET',
dataType: 'json',
success: onDataReceived
});
});
// initiate a recurring data update
$("input.dataUpdate").click(function () {
// reset data
data = [];
alreadyFetched = {};
$.plot(placeholder, data, options);
var iteration = 0;
function fetchData() {
++iteration;
function onDataReceived(series) {
// we get all the data in one go, if we only got partial
// data, we could merge it with what we already got
data = [ series ];
$.plot($("#placeholder"), data, options);
}
$.ajax({
// usually, we'll just call the same URL, a script
// connected to a database, but in this case we only
// have static example files so we need to modify the
// URL
url: "data-usa-gdp-growth-" + iteration + ".json",
method: 'GET',
dataType: 'json',
success: onDataReceived
});
if (iteration < 5)
setTimeout(fetchData, 1000);
else {
data = [];
alreadyFetched = {};
}
}
setTimeout(fetchData, 1000);
});
});
</script>
Tag : JavaScript, Ajax, jQuery, JAVA, JSP
|
ประวัติการแก้ไข 2013-09-04 19:20:44 2013-09-04 19:21:29
|
 |
 |
 |
 |
Date :
2013-09-04 17:29:48 |
By :
ztarzenithz |
View :
1057 |
Reply :
6 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ปัญหาคือคนอื่นรันไม่ได้ มันจะช่วยได้ยากน่ะครับ 
|
 |
 |
 |
 |
Date :
2013-09-05 06:34:58 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|