0
votes

I would like to know, how can we encode the MYSQL data into JSONP data using php. We have also include the JSONP class. Please look at the code below for creating 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 . ');'; 
?> 

Please see the exact values for making the above codes, it's returning these values. (octave-global.com/portal/tool/index.php )

Actually, our requirement to get these values for Kendo-UI based programe, like we mentioned below.

<!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>

It's not working, when we read This URL :- octave-global.com/portal/tool/ It's only work with this URL :- demos.kendoui.com/service/Products .

Please suggest me how can we make my PHP configuaration based on this URL demos.kendoui.com/service/Products .

Thanks

ROD

1

1 Answers

0
votes

Syntax errors aside, you need to switch your content type to application/javascript or application/x-javascript. Your requests for JSONP (via Kendo UI) are evaluated by the JavaScript interpreter. They are not parsed by a JSON parser.