-
- $.ajax({
- url: 'query.php',
- data: {id:10},
- datatype: json
- success: function(results) {
- if (results.msg == 'success) ') {
- for (var i in data) {
- $('#content').append(
- 'id = ' + results.data[i].id + ', description = ' + results.data[i] .description + ', msrp = ' + results.data[i].msrp
- );
- }
- } else {
- $('#content').append(results.msg);
- }
- }
- });
复制代
php代:
-
-
- if (isset($_GET['id'])) {
- $sql = "SELECT id、説明、msrp FROM tbl WHERE id = '{$_GET['id'] }'";
- $return = array();
- if ($result = mysql_query($sql)) {
- if (mysql_num_rows($result)) {
- $return['msg'] = 'success';
- while ($row = mysql_fetch_assoc($result)) {
- $return['data'][] = $row;
- }
- } else {
- $return['msg'] = '結果が見つかりません';
- } else {
- $return['msg'] = 'クエリが失敗しました';
- }
- header("Content-type: application/json");
- echo json_encode($result);
- }
复制代
|