서버 코드 예제
다음 섹션은 SQL 데이터를 가져 오는 데 사용되는 서버 코드 목록입니다.
1. PHP와 MySQL 사용하기. JSON 반환.
2. PHP와 MS Access 사용하기. JSON 반환.
3. ASP.NET, VB 및 MS Access 사용. JSON 반환.
4. ASP.NET, Razor 및 SQL Lite 사용. JSON 반환.
교차 사이트 HTTP 요청
요청하는 페이지가 아닌 다른 서버의 데이터 요청은 사이트 간 HTTP 요청 이라고 합니다.
교차 사이트 요청은 웹에서 일반적입니다. 많은 페이지가 다른 서버의 CSS, 이미지 및 스크립트를로드합니다.
최신 브라우저에서는 보안상의 이유로 스크립트의 사이트 간 HTTP 요청 이 동일한 사이트 로 제한됩니다 .
다음 예제는 PHP 예제에서 사이트 간 액세스를 허용하도록 추가되었습니다.
header("Access-Control-Allow-Origin: *");
1. 서버 코드 PHP와 MySQL
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
$conn = new mysqli("myServer", "myUser", "myPassword", "Northwind");
$result = $conn->query("SELECT CompanyName, City, Country FROM Customers");
$outp = "";
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
if ($outp != "") {$outp .= ",";}
$outp .= '{"Name":"' . $rs["CompanyName"] . '",';
$outp .= '"City":"' . $rs["City"] . '",';
$outp .= '"Country":"'. $rs["Country"] . '"}';
}
$outp ='{"records":['.$outp.']}';
$conn->close();
echo($outp);
?>
2. 서버 코드 PHP 및 MS 액세스
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=ISO-8859-1");
$conn = new COM("ADODB.Connection");
$conn->open("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=Northwind.mdb");
$rs = $conn->execute("SELECT CompanyName, City, Country FROM Customers");
$outp = "";
while (!$rs->EOF) {
if ($outp != "") {$outp .= ",";}
$outp .= '{"Name":"' . $rs["CompanyName"] . '",';
$outp .= '"City":"' . $rs["City"] . '",';
$outp .= '"Country":"'. $rs["Country"] . '"}';
$rs->MoveNext();
}
$outp ='{"records":['.$outp.']}';
$conn->close();
echo ($outp);
?>
3. 서버 코드 ASP.NET, VB 및 MS 액세스
<%@ Import Namespace="System.IO"%>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb"%>
<%
Response.AppendHeader("Access-Control-Allow-Origin", "*")
Response.AppendHeader("Content-type", "application/json")
Dim conn As OleDbConnection
Dim objAdapter As OleDbDataAdapter
Dim objTable As DataTable
Dim objRow As DataRow
Dim objDataSet As New DataSet()
Dim outp
Dim c
conn = New OledbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=Northwind.mdb")
objAdapter = New OledbDataAdapter("SELECT CompanyName, City, Country FROM Customers", conn)
objAdapter.Fill(objDataSet, "myTable")
objTable=objDataSet.Tables("myTable")
outp = ""
c = chr(34)
for each x in objTable.Rows
if outp <> "" then outp = outp & ","
outp = outp & "{" & c & "Name" & c & ":" & c & x("CompanyName") & c & ","
outp = outp & c & "City" & c & ":" & c & x("City") & c & ","
outp = outp & c & "Country" & c & ":" & c & x("Country") & c & "}"
next
outp ="{" & c & "records" & c & ":[" & outp & "]}"
response.write(outp)
conn.close
%>
4. Server Code ASP.NET, Razor C # 및 SQL Lite
@{
Response.AppendHeader("Access-Control-Allow-Origin", "*")
Response.AppendHeader("Content-type", "application/json")
var db = Database.Open("Northwind");
var query = db.Query("SELECT CompanyName, City, Country FROM Customers");
var outp =""
var c = chr(34)
}
@foreach(var row in query){
if (outp != "") {outp = outp + ","}
outp = outp + "{" + c + "Name" + c + ":" + c + @row.CompanyName + c + ","
outp = outp + c + "City" + c + ":" + c + @row.City + c + ","
outp = outp + c + "Country" + c + ":" + c + @row.Country + c + "}"
}
outp ="{" + c + "records" + c + ":[" + outp + "]}"
@outp
다음 섹션은 SQL 데이터를 가져 오는 데 사용되는 서버 코드 목록입니다.
1. PHP와 MySQL 사용하기. JSON 반환.
2. PHP와 MS Access 사용하기. JSON 반환.
3. ASP.NET, VB 및 MS Access 사용. JSON 반환.
4. ASP.NET, Razor 및 SQL Lite 사용. JSON 반환.
교차 사이트 HTTP 요청
요청하는 페이지가 아닌 다른 서버의 데이터 요청은 사이트 간 HTTP 요청 이라고 합니다.
교차 사이트 요청은 웹에서 일반적입니다. 많은 페이지가 다른 서버의 CSS, 이미지 및 스크립트를로드합니다.
최신 브라우저에서는 보안상의 이유로 스크립트의 사이트 간 HTTP 요청 이 동일한 사이트 로 제한됩니다 .
다음 예제는 PHP 예제에서 사이트 간 액세스를 허용하도록 추가되었습니다.
header("Access-Control-Allow-Origin: *");
1. 서버 코드 PHP와 MySQL
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
$conn = new mysqli("myServer", "myUser", "myPassword", "Northwind");
$result = $conn->query("SELECT CompanyName, City, Country FROM Customers");
$outp = "";
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
if ($outp != "") {$outp .= ",";}
$outp .= '{"Name":"' . $rs["CompanyName"] . '",';
$outp .= '"City":"' . $rs["City"] . '",';
$outp .= '"Country":"'. $rs["Country"] . '"}';
}
$outp ='{"records":['.$outp.']}';
$conn->close();
echo($outp);
?>
2. 서버 코드 PHP 및 MS 액세스
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=ISO-8859-1");
$conn = new COM("ADODB.Connection");
$conn->open("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=Northwind.mdb");
$rs = $conn->execute("SELECT CompanyName, City, Country FROM Customers");
$outp = "";
while (!$rs->EOF) {
if ($outp != "") {$outp .= ",";}
$outp .= '{"Name":"' . $rs["CompanyName"] . '",';
$outp .= '"City":"' . $rs["City"] . '",';
$outp .= '"Country":"'. $rs["Country"] . '"}';
$rs->MoveNext();
}
$outp ='{"records":['.$outp.']}';
$conn->close();
echo ($outp);
?>
3. 서버 코드 ASP.NET, VB 및 MS 액세스
<%@ Import Namespace="System.IO"%>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb"%>
<%
Response.AppendHeader("Access-Control-Allow-Origin", "*")
Response.AppendHeader("Content-type", "application/json")
Dim conn As OleDbConnection
Dim objAdapter As OleDbDataAdapter
Dim objTable As DataTable
Dim objRow As DataRow
Dim objDataSet As New DataSet()
Dim outp
Dim c
conn = New OledbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=Northwind.mdb")
objAdapter = New OledbDataAdapter("SELECT CompanyName, City, Country FROM Customers", conn)
objAdapter.Fill(objDataSet, "myTable")
objTable=objDataSet.Tables("myTable")
outp = ""
c = chr(34)
for each x in objTable.Rows
if outp <> "" then outp = outp & ","
outp = outp & "{" & c & "Name" & c & ":" & c & x("CompanyName") & c & ","
outp = outp & c & "City" & c & ":" & c & x("City") & c & ","
outp = outp & c & "Country" & c & ":" & c & x("Country") & c & "}"
next
outp ="{" & c & "records" & c & ":[" & outp & "]}"
response.write(outp)
conn.close
%>
4. Server Code ASP.NET, Razor C # 및 SQL Lite
@{
Response.AppendHeader("Access-Control-Allow-Origin", "*")
Response.AppendHeader("Content-type", "application/json")
var db = Database.Open("Northwind");
var query = db.Query("SELECT CompanyName, City, Country FROM Customers");
var outp =""
var c = chr(34)
}
@foreach(var row in query){
if (outp != "") {outp = outp + ","}
outp = outp + "{" + c + "Name" + c + ":" + c + @row.CompanyName + c + ","
outp = outp + c + "City" + c + ":" + c + @row.City + c + ","
outp = outp + c + "Country" + c + ":" + c + @row.Country + c + "}"
}
outp ="{" + c + "records" + c + ":[" + outp + "]}"
@outp
게시글 목록
| 번호 | 제목 |
|---|---|
| 1326 |
AngularJS
AngularJS Filters에 uppercase (대문자변환)
|
| 1325 |
AngularJS
AngularJS Scope 3
|
| 1324 |
AngularJS
AngularJS Scope 2
|
| 1323 |
AngularJS
AngularJS Scope 1
|
| 1322 | |
| 1321 | |
| 1320 |
AngularJS
AngularJS Controllers
|
| 1319 |
AngularJS
AngularJS Data Binding 2번째
|
| 1318 | |
| 1317 |
AngularJS
AngularJS ng-model Directive
|
| 1316 | |
| 1315 |
AngularJS
AngularJS Directives(지시문) - 데이터 바인딩
|
| 1314 |
AngularJS
AngularJS Directives(지시문)
|
| 1313 |
AngularJS
AngularJS 모듈 만들기
|
| 1312 |
AngularJS
앵큘러js 간단한 예제
|
| 1311 | |
| 1310 |
AngularJS
AngularJS Input Controls - Data-Binding
|
| 1309 |
AngularJS
AngularJS $event Object
|
| 1308 |
AngularJS
AngularJS Toggle, True/False
|
| 1307 |
AngularJS
AngularJS ng-click 지시문
|
| 1306 |
AngularJS
AngularJS 마우스 이벤트
|
| 1305 |
AngularJS
AngularJS 이벤트
|
| 1304 |
jQuery Mobile
scrollstart 이벤트
|
| 1303 |
jQuery Mobile
pageshow 이벤트
|
| 1302 |
jQuery Mobile
pageremove 이벤트
|
| 1301 |
jQuery Mobile
pageloadfailed 이벤트
|
| 1300 |
jQuery Mobile
pageload 이벤트
|
| 1299 |
jQuery Mobile
pageinit 이벤트
|
| 1298 |
jQuery Mobile
pagehide 이벤트
|
| 1297 |
jQuery Mobile
pagecreate
|
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기