2

I have a url encoded string i'm sending to php via the jQuery AJAX API that appears to be getting automatically decoded and passed to the server.

Ajax Call:

var requestXML = '<searchString>red%20ford%5BimpoundState%3Ain%5D</searchString>';
$.ajax({
 data: "query=" + requestXML,
 success: function(response)
 {
     //alerts <searchString>red%20ford%5BimpoundState%3Ain%5D</searchString>
     alert(requestXML);
 }
});

Inspecting the request in the chrome dev tools shows its being decodedalt text

I'm a bit lost here, I read a bit about jQuery processing data, but i turned that off via {processData: false} but i got no results.

-Thanks for any help!

UPDATE:

My backend is currently set up to parse xml with url encoded values.

Like: <searchString>red%20ford%5BimpoundState%3Ain%5D</searchString>

When i pass data: {query: requestXML} i get...

This:%3CsearchString%3Ered%20ford%5BimpoundState%3Ain%5D%3C%2searchString%3E (url encoded xml).

The real issue is when i'm generating this XML I encode the values, but jQuery seems to decode them in the request.

1 Answer 1

2

You can use data: {query: requestXML}, to pass the parameters and they get url encoded by jQuery.

The point is the the param gets attached to the url as-is if it already a string.

Quote

data (Object, String)

Data to be sent to the server. It is converted to a query string, if not already a string. It's appended to the url for GET-requests. See processData option to prevent this automatic processing. Object must be Key/Value pairs. If value is an Array, jQuery serializes multiple values with same key based on the value of the traditional setting (described below).

Since you use GET method, your params get added to the URL string. The decoding then happens from the browser and not from jQuery.

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

2 Comments

no... i'm not using the get method. although my code doesn't reflect this (not all ajaxoptions are included), I'm explicitly setting it to post in the ajax call.
@Derek.. hmmm. You still use the {processData: false} ?

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.