【发布时间】:2017-03-20 01:44:39
【问题描述】:
感谢您说出您对这种神秘行为的看法:
此代码有效:
JS 代码:
$.ajax({
url: "ajouterEntreeParExcel.ajax.php", // url de la page à charger
data: {"name":"John","date":"05 & 06 mars"},
cache: false, // pas de mise en cache
async: false,
contentType : "application/json",
dataType: "json",
success:function(jsonRetour){
},
error:function(XMLHttpRequest, textStatus, errorThrows){ // erreur durant la requete
}
});
还有 PHP 代码:
$name = $_GET["nom"];
$date = $_GET["date"];
这个不行
var dataAjax = {};
dataAjax["name"] = "John";
dataAjax["date"] = "05 & 06 mars";
var entree = JSON.stringify(dataAjax);
$.ajax({
url: "ajouterEntreeParExcel.ajax.php", // url de la page à charger
data: entree,
cache: false, // pas de mise en cache
async: false,
contentType : "application/json",
dataType: "json",
success:function(jsonRetour){
},
error:function(XMLHttpRequest, textStatus, errorThrows){ // erreur durant la requete
}
});
使用相同的 PHP 代码。 在 Debug with firebug 中,我检查了变量“entre”,它的格式很好,但我在 PHP 端没有得到任何东西。
注意:我更喜欢使用 GET 类型而不是 POST 类型。
有什么想法吗?
【问题讨论】:
-
永远不要使用
async: false!这是一种糟糕的做法,现在已被弃用
标签: php jquery ajax get stringify