0

PHPを使用してMYSQLデータをJSONPデータにエンコードする方法を知りたいです。JSONP クラスも含まれています。JSONP を作成するには、以下のコードを参照してください。

<?php
require('JSON.php'); 
$link = mysql_pconnect("localhost", "root", "") or die("Unable To Connect To Database Server");
mysql_select_db("users") or die("Unable To Connect To Northwind");
// add the header line to specify that the content type is JSON
// determine the request type
header("Content-type: application/json");  

$sth = mysql_query("SELECT ID, Title FROM ldr");

$rows = array();
while($r = mysql_fetch_assoc($sth)) {
    $data[] = $r;
}
//print json_encode($rows);

$encoder = new Services_JSON();  
$json = $encoder->encode($data);  

echo 'callback(' . $json . ');'; 
?> 

上記のコードを作成するための正確な値を参照してください。これらの値が返されます。(octave-global.com/portal/tool/index.php )

実際には、Kendo-UI ベースのプログラムでこれらの値を取得する必要があります。これについては、以下で説明します。

<!DOCTYPE html>
<html>
<head>
    <title></title>
<script src="js/jquery.min.js"></script>
    <script src="js/kendo.all.js"></script>
    <link href="css/kendo.common.css" rel="stylesheet" />
    <link href="css/kendo.default.css" rel="stylesheet" />
</head>
<body>
            <div id="example" class="k-content">
            <div id="grid"></div>

            <script>
                   $(document).ready(function () {

                        dataSource = new kendo.data.DataSource({
                            transport: {
                                read:{
                                url: "http://www.octave-global.com/portal/tool/",
                                 dataType: "jsonp"
                                },
                                update: {
                                  url: "data/update.php",
                                  dataType: "jsonp"
                                },
                                destroy: {
                                    url:"data/update.php",
                                    dataType: "jsonp"
                                },
                                create: {
                                    url: "data/save.php",
                                    dataType: "jsonp"
                                },
                                parameterMap: function(options, operation) {
                                    if (operation !== "read" && options.models) {
                                        return {models: kendo.stringify(options.models)};
                                    }
                                }
                            },
                            batch: true,
                            pageSize: 10,
                            schema: {
                           model: {
                                     model: {
                                id: "ID",
                                fields: {
                                    Title: { editable: true},
                                    }
                    }
                        }
                    });

              $("#grid").kendoGrid({
                    dataSource: dataSource,
                    navigatable: true,
                    pageable: true,
                    height: 400,
                    toolbar: ["create", "save", "cancel"],
                    columns: [
                        "Title",
                       { command: "destroy", title: " ", width: "110px" }],
                    editable: true
                });
            });
        </script>
    </div>


</body>
 </html>

この URL :- octave-global.com/portal/tool/ を読み取ると、機能しません。この URL でのみ機能します:- demos.kendoui.c​​om/service/Products 。

この URL demos.kendoui.c​​om/service/Products に基づいて PHP 構成を作成する方法を教えてください。

ありがとう

ロッド

4

1 に答える 1

0

構文エラーは別として、コンテンツ タイプをapplication/javascriptまたはapplication/x-javascriptに切り替える必要があります。JSONP に対する (Kendo UI 経由の) リクエストは、JavaScript インタープリターによって評価されます。それらは JSON パーサーによって解析されません。

于 2012-03-13T23:56:23.943 に答える