2011-03-30 86 views
1

我送从jQuery的自定义XML数据的Drupal/PHP如下:停止自动URL解码

$.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标记中包含的网址,所以我对其编码,并作出一个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调用发送的数据执行任何自动操作。如何阻止这种行为?我觉得我缺少这里的一些基本概念......

回答

2

$ _POST数据以$ _GET相同的方式发送到服务器。它必须发送urlencoded否则它可能会中断。这意味着,默认情况下,PHP会解码urlencodes,因为它期望数据被urlencoded。