2012-03-09 9 views
0

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

<?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)

実際、私たちは以下のように、剣道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の設定を行う方法を教えてください。

おかげ

RODは

答えて

0

構文エラーはさておき、あなたはアプリケーション/ javascriptのまたはアプリケーション/ X-javascriptのにあなたのコンテンツタイプを切り替える必要があります。 JSONPのリクエスト(剣道UI経由)は、JavaScriptインタプリタによって評価されます。それらはJSONパーサーによって解析されません。

関連する問題