我用 ajax 将 id 发送到 php 端。php 端应该使用具有此 ID 的 MySql 行来回答。
阿贾克斯:
$.ajax({
dataType : 'jsonp',
type: "POST",
async: false,
traditional: true,
jsonpCallback: 'jsonCallback',
contentType: "application/json",
data : {
'ID' : '2'
},
url : 'http://myside.de/sqlExecute.php',
success : function(sqlArray) {
console.log("Eingange " +sqlArray.ID);
console.log("Eingange " +sqlArray.Name);
},
error: function(a){
alert("error");
}
});
php:
<?php
include('DatabaseConnector.php');
$array = toString('SELECT * FROM `RMap` WHERE `ID` ='+$_POST["ID"]);
$json = json_encode($array);
print $_GET['callback'] . "(" . $json . ")"
?>
这有效:
<?php
include('DatabaseConnector.php');
$array = toString('SELECT * FROM `RMap` WHERE `ID` =2');
$json = json_encode($array);
print $_GET['callback'] . "(" . $json . ")"
?>
$_Post 变体有什么问题?
谢谢
更新
现在我收到错误消息“200 错误:未调用 jsonCallback”,代码如下:
<?php
include('DatabaseConnector.php');
$array = toString('SELECT * FROM `RMap` WHERE `ID` ='.$_POST["ID"]);
$json = json_encode($array);
print $_GET['callback'] . "(" . $json . ")"
?>