Я хотел бы знать, как мы можем кодировать данные MYSQL в данные JSONP с помощью php. Мы также включили класс 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.com/service/Products.
Пожалуйста, предложите мне, как мы можем настроить PHP на основе этого URL demos.kendoui.com/service/Products.
Спасибо
ROD