1

I am sending a custom XML data from jQuery to Drupal/PHP as follows:

$.ajax({
            type: 'POST',       
            url: this.href,

            success: function(data){ 

                alert('Form is successfully saved');


            },
            error:function(XMLHttpRequest, textStatus,  errorThrown){
                alert("Error");

            },

            data: 'myxml='+ mydata 
        });

My XML tags contains URLs, so I encode them, and before making an AJAX call, data looks somewhat like this:

mydata="<txtLinkLocation>http%3A%2F%2Fportal.cubewerx.com%2Fcubewerx%2Fcubeserv%2Fcubeserv.cgi%3FCONFIG%3Dhaiti%26SERVICE%3DWFS%26DATASTORE%3DOSM%26request%3DGetCapabilities</txtLinkLocation>";

And, in PHP I get the received data, and I store it as follows:

$receivedXML = $_POST['myxml'];

Now, contains of $receivedXML looks like this:

<txtLinkLocation>http://portal.cubewerx.com/cubewerx/cubeserv/cubeserv.cgi?CONFIG=haiti&SERVICE=WFS&DATASTORE=OSM&request=GetCapabilities</txtLinkLocation>

My question is why URL inside this string is being been automatically decoded? Why is this happening? I do not want any automatic operation to be performed on data that is being sent through AJAX call. How to stop this behavior? I feel like I am missing some fundamental concepts here...

2 Answers 2

2

$_POST data is sent to the server in the same way as $_GET. It has to be sent urlencoded else it may break. This means that by default, PHP will decode urlencodes because it expects the data to be urlencoded.

Sign up to request clarification or add additional context in comments.

Comments

1

PHP decodes $_GET and $_REQUEST data it by default, see the note in urldecoding on auto-encoding server variables. Turns out that $_POST does too.

Solution: urlencode() your data again if you want it to be encoded.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.