일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- MySQL
- 가우스
- JDOM
- phonegap
- JSON
- MFC
- 선택적조인
- appspresso
- jsr 296
- GPS
- iBATIS
- ibsheet
- Android
- Eclipse
- WebLogic
- sencha touch
- Struts
- oracle
- PHP
- Spring
- 전자정부프레임워크
- node.js
- tomcat
- dock
- Ajax
- jQuery
- swingx
- Google Map
- PLSQL
- rowspan
Archives
- Today
- Total
Where The Streets Have No Name
jquery에서 json데이터 처리 본문
php source :
<?
$name = $_GET[name];
header("Content-type: text/html;charset=utf-8");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
include "../lib/config.php";
include "../lib/json.php";
include "../lib/db_class.php";
$Database = new TDatabase("$DB_Host", "$DB_User", "$DB_Password", "$DB_Name");
$Database->Open();
$Query = new TQuery($Database);
$Query->SQL = " SELECT * ".
" FROM am_shop_good ".
" WHERE gd_name like '%$name%' ".
" ORDER BY no DESC";
$Query->Open($Query->SQL);
$output = array();
while (!$Query->EOF) {
$row = array("no"=>$Query->FieldByName("no"),
"st_code"=>$Query->FieldByName("st_code"),
"gd_name"=>$Query->FieldByName("gd_name"),
"gd_1_img"=>$Query->FieldByName("gd_1_img"),
"gd_s_img"=>$Query->FieldByName("gd_s_img"));
array_push($output, $row);
$Query->Next();
}
$Query->Close();
//print($json->encode($output3));
echo iconv("CP949","UTF-8", json_encode2($output));
?>
html source :
html>
<head>
<script type="text/javascript" src="/shop/js/jquery.js"></script>
<script type="text/javascript" src="/shop/js/jquery.blockUI.js"></script>
<script type="text/javascript" src="/shop/js/base64.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#msg").ajaxError(function(event, request, settings){
$("#msg").append("<li>Error requesting page : " + settings.url + "</li>");
});
$("#msg").ajaxStart(function(){
$("#msg").empty();
$("#goodResult").empty();
});
//에러여부에 상관없이 작업요청후 끝난후 실행
$("#msg").ajaxStop(function(){
var now = new Date();
var stopTime = now.toLocaleString()+':'+now.getMilliseconds()+'ms';
$("#msg").append("stop : "+stopTime);
$.unblockUI();
});
$('#btnGoodSearch').click(function() {
$.blockUI({ message: '<spanstyle="font-size:15px;font-weight:bold"><imgsrc="/shop/images/busy.gif" /> 처리중......</span>' });
$.ajax({
type: "GET",
url: "test6_ds.php",
data: "name="+$('#txtSearch').get(0).value,
dataType: "json",
cache: false ,
success: function(data){
$.each(data, function(i,val){
tmp = '<tr>'+
'<td>'+(i+1)+'</td>'+
'<td><a href="/shop/good_view.php?mode=view&code='+val.st_code+'&no='+val.no+'" target=_blank><img src="/shop/'+val.gd_1_img+'" border=0></a><br>'+val.gd_name+'</td>'+
'<tr>';
$(tmp).appendTo("#goodResult");
});
}
});
});
});
</script>
</head>
<body>
<div id="msg"></div>
<input type="text" id="txtSearch">
<input type="button" id="btnGoodSearch" value="상품조회">
<table id="goodResult" border="1"></table>
</html>
<?
$name = $_GET[name];
header("Content-type: text/html;charset=utf-8");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
include "../lib/config.php";
include "../lib/json.php";
include "../lib/db_class.php";
$Database = new TDatabase("$DB_Host", "$DB_User", "$DB_Password", "$DB_Name");
$Database->Open();
$Query = new TQuery($Database);
$Query->SQL = " SELECT * ".
" FROM am_shop_good ".
" WHERE gd_name like '%$name%' ".
" ORDER BY no DESC";
$Query->Open($Query->SQL);
$output = array();
while (!$Query->EOF) {
$row = array("no"=>$Query->FieldByName("no"),
"st_code"=>$Query->FieldByName("st_code"),
"gd_name"=>$Query->FieldByName("gd_name"),
"gd_1_img"=>$Query->FieldByName("gd_1_img"),
"gd_s_img"=>$Query->FieldByName("gd_s_img"));
array_push($output, $row);
$Query->Next();
}
$Query->Close();
//print($json->encode($output3));
echo iconv("CP949","UTF-8", json_encode2($output));
?>
html source :
html>
<head>
<script type="text/javascript" src="/shop/js/jquery.js"></script>
<script type="text/javascript" src="/shop/js/jquery.blockUI.js"></script>
<script type="text/javascript" src="/shop/js/base64.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#msg").ajaxError(function(event, request, settings){
$("#msg").append("<li>Error requesting page : " + settings.url + "</li>");
});
$("#msg").ajaxStart(function(){
$("#msg").empty();
$("#goodResult").empty();
});
//에러여부에 상관없이 작업요청후 끝난후 실행
$("#msg").ajaxStop(function(){
var now = new Date();
var stopTime = now.toLocaleString()+':'+now.getMilliseconds()+'ms';
$("#msg").append("stop : "+stopTime);
$.unblockUI();
});
$('#btnGoodSearch').click(function() {
$.blockUI({ message: '<spanstyle="font-size:15px;font-weight:bold"><imgsrc="/shop/images/busy.gif" /> 처리중......</span>' });
$.ajax({
type: "GET",
url: "test6_ds.php",
data: "name="+$('#txtSearch').get(0).value,
dataType: "json",
cache: false ,
success: function(data){
$.each(data, function(i,val){
tmp = '<tr>'+
'<td>'+(i+1)+'</td>'+
'<td><a href="/shop/good_view.php?mode=view&code='+val.st_code+'&no='+val.no+'" target=_blank><img src="/shop/'+val.gd_1_img+'" border=0></a><br>'+val.gd_name+'</td>'+
'<tr>';
$(tmp).appendTo("#goodResult");
});
}
});
});
});
</script>
</head>
<body>
<div id="msg"></div>
<input type="text" id="txtSearch">
<input type="button" id="btnGoodSearch" value="상품조회">
<table id="goodResult" border="1"></table>
</html>