我将一个定制的XML数据从jQuery发送到Drupal/PHP,如下所示:
$.ajax({
type: 'POST',
url: this.href,
success: function(data){
alert('Form is successfully saved');
},
error:function(XMLHttpRequest, textStatus, errorThrown){
alert("Error");
},
data: 'myxml='+ mydata
});
我的XML标记包含URL,所以我对它们进行了编码,在进行AJAX调用之前,数据看起来有点像这样:
mydata="<txtLinkLocation>http%3A%2F%2Fportal.cubewerx.com%2Fcubewerx%2Fcubeserv%2Fcubeserv.cgi%3FCONFIG%3Dhaiti%26SERVICE%3DWFS%26DATASTORE%3DOSM%26request%3DGetCapabilities</txtLinkLocation>";
在PHP中,我获得接收到的数据,并按如下方式存储它:
$receivedXML = $_POST['myxml'];
现在,包含的$receivedXML如下所示:
<txtLinkLocation>http://portal.cubewerx.com/cubewerx/cubeserv/cubeserv.cgi?CONFIG=haiti&SERVICE=WFS&DATASTORE=OSM&request=GetCapabilities</txtLinkLocation>
我的问题是为什么这个字符串中的URL会被自动解码?为什么会发生这种情况?我不希望对通过AJAX调用发送的数据执行任何自动操作。如何停止这种行为?我觉得我在这里遗漏了一些基本概念...
发布于 2011-03-30 23:12:07
$_POST数据以与$_GET相同的方式发送到服务器。必须对其进行urlencoded发送,否则它可能会崩溃。这意味着在默认情况下,PHP将对urlencoded进行解码,因为它需要对数据进行urlencoded。
发布于 2011-03-30 23:15:27
默认情况下,PHP解码$_GET和$_REQUEST数据,参见the note in urldecoding on auto-encoding server variables。事实证明,$_POST也是如此。
解决方案:如果您希望对数据进行编码,请再次使用urlencode()
。
https://stackoverflow.com/questions/5493536
复制相似问题