我正在与jquery/JS和PHP进行简单的客户机/服务器通信。它工作正常,直到数据中包含'.'
。jquery/js和php通信问题
试着用下面的标题:
asdf-wq1 --> works
test1 --> works
bigip1.local --> '.' is replaced with '_'
我已经添加了escape()
功能,我的代码,但结果是一样的。
function xy(){
for (var i = 0; i < nodes.length; i++) {
var xy = escape(nodes[i].title) +"=" +escape(nodes[i].translate.x + "/" + nodes[i].translate.y);
$.ajax({
url: 'save_layout.php',
data: xy,
dataType: "text",
type: 'post',
success: function(output) {
$("#output").html(output);
},
error: function (response, status, error) {
alert("error" + response.responseText);
}
});
}
}
PHP:
foreach($_POST as $name=>$value) {
echo "$name $value \n";
}
Firebug的输出请求:
POST http /frontend/save_layout.php 200 OK 186ms jquery....min.js (Zeile 4) HeaderPostAntwortHTML Parameterapplication/x-www-form-urlencoded bigip1.local 470/390 Quelle bigip1.local=470/390
Firebug的输出(响应):
bigip1_local 470/390
正如你所看到的 - 它似乎被送到到服务器正确,但在服务器上就像读到我们的$_POST
- '.'
是一个'_'
突然。
希望有人能帮助我这里!
尝试让jQuery进行编码:var xy = {}; xy [nodes [i] .title] = nodes [i] .translate.x +“/”+ nodes [i] .translate.y;'这样jQuery就会为您发布帖子正文。 – Chad
嗨! THX为即时响应 - 但不幸的是我仍然面临同样的问题...我可以看到正确的价值“bigip1.local”在萤火虫发布数据,但在PHP中,我仍然得到“bigip1_local”只要我访问$ _POST ... – roegi